Skip to content

Commit

Permalink
Merge pull request #148 from Remmeauth/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiia-bilova authored Sep 30, 2019
2 parents c808c4c + 44de90b commit 656f533
Show file tree
Hide file tree
Showing 33 changed files with 911 additions and 22 deletions.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,54 @@ $ curl -X POST -H "Content-Type: application/json" \
| email | Input arguments validation | This field is required. | 400 |
| password | Input arguments validation | This field is required. | 400 |

* `POST | /users/email/confirm/` - request email confirm at the specified email address. Send the confirm link to the e-mail address.

##### Request parameters

| Arguments | Type | Required | Description |
| :-------: | :----: | :------: | ------------ |
| email | String | Yes | User e-mail. |

```bash
$ curl -X POST -d '{"email":"dmytro.striletskyi@gmail.com"}' \
-H "Content-Type: application/json" \
http://localhost:8000/users/email/confirm/ | python -m json.tool
{
"result": "Message with confirmed registration link has been sent to the specified e-mail address."
}
```

##### Known errors

| Argument | Level | Error message | Status code |
| :------: | :------------------------: | -------------------------------------------------- | :---------: |
| - | General execution | User with specified e-mail address does not exist. | 400 |
| email | Input arguments validation | This field is required. | 400 |

* `POST | /users/email/confirm/{user_identifier}/` - confirm registration at the specified user identifier.

##### Request parameters

| Arguments | Type | Required | Description |
| :-------------: | :----: | :------: | ---------------- |
| user_identifier | String | Yes | User identifier. |

```bash
$ curl -X POST http://localhost:8000/users/email/confirm/4b73ab1fc1f94c719420433e69408609/ \
-H "Content-Type: application/json" | python -m json.tool
{
"result": "Registration is confirmed by the specified identifier."
}
```

##### Known errors

| Argument | Level | Error message | Status code |
| :------: | :------------------------: | ------------------------------------------------- | :---------: |
| - | General execution | User with specified identifier does not exist. | 400 |
| - | General execution | User with specified identifier already confirmed. | 400 |
| email | Input arguments validation | This field is required. | 400 |

* `GET | /users/{username}/` - get user by username.

##### Request parameters
Expand All @@ -109,6 +157,7 @@ $ curl -H "Content-Type: application/json" http://localhost:8000/users/dmytro.st
"email": "dmytro.striletskyi@gmail.com",
"id": 6,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -284,6 +333,7 @@ $ curl -H "Content-Type: application/json" http://localhost:8000/users/john.smit
"email": "john.smith@gmail.com",
"id": 5,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -391,13 +441,15 @@ $ curl http://localhost:8000/block-producers/2/ -H "Content-Type: application/js
"short_description": "Leading Block Producer - founded by a team of serial tech entrepreneurs, headquartered in Canada",
"slack_url": "https://slack.com/bpcanada",
"status": "active",
"status_description": "",
"steemit_url": "https://steemit.com/@bpcanada",
"telegram_url": "https://t.me/bpcanada",
"twitter_url": "https://twitter.com/bpcanada",
"user": {
"email": "tony.stark@gmail.com",
"id": 2,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -436,13 +488,15 @@ $ curl http://localhost:8000/block-producers/ -H "Content-Type: application/json
"short_description": "Leading Block Producer - founded by a team of serial tech entrepreneurs, headquartered in USA",
"slack_url": "https://slack.com/bpusa",
"status": "active",
"status_description": "",
"steemit_url": "https://steemit.com/@bpusa",
"telegram_url": "https://t.me/bpusa",
"twitter_url": "https://twitter.com/bpusa",
"user": {
"email": "tony.stark@gmail.com",
"id": 2,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -512,6 +566,7 @@ $ curl -X PUT http://localhost:8000/block-producers/ \
"email": "dmytro.striletskyi@gmail.com",
"id": 5,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -606,6 +661,31 @@ $ curl -X DELETE -H "Content-Type: application/json" \
| username | Input arguments validation | User has no authority to delete this block producer by its identifier. | 400 |


* `POST | /block-producers/{block_producer_identifier}/description/` - send message to email with a description of the reason for the rejection of the block producer.

##### Request parameters

| Arguments | Type | Required | Description |
| :-----------------------: | :-----: | :------: | ----------------------------- |
| block_producer_identifier | Integer | Yes | Identifier of block producer. |
| email | String | Yes | User e-mail. |

```bash
$ curl -X POST -d '{"email":"dmytro.striletskyi.1337@gmail.com"}' \
-H "Content-Type: application/json" \
http://localhost:8000/block-producers/2/description/ | python -m json.tool
{
"result": "Message was sent to the specified email address with a description of the reason for the rejection of the block producer."
}
```

##### Known errors

| Arguments | Level | Error message | Status code |
| :-----------------------: | :------------------------: | -------------------------------------------------------- | :---------: |
| email | Input arguments validation | User with specified e-mail address does not exist. | 400 |
| block_producer_identifier | Input arguments validation | Block producer with specified identifier does not exist. | 400 |

* `GET | /block-producers/search/?phrase=block%20producer%20usa` - search block producers by phrase.

##### Request parameters
Expand Down Expand Up @@ -639,6 +719,7 @@ $ curl http://localhost:8000/block-producers/search/?phrase=block%20producer%20u
"email": "tony.stark@gmail.com",
"id": 2,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -715,6 +796,7 @@ $ curl -H "Content-Type: application/json" http://localhost:8000/block-producers
"email": "john.smith@gmail.com",
"id": 1,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down Expand Up @@ -772,6 +854,7 @@ $ curl -H "Content-Type: application/json" http://localhost:8000/block-producers
"email": "paul.rudd@gmail.com",
"id": 3,
"is_active": true,
"is_email_confirmed": true,
"is_staff": false,
"is_superuser": false,
"last_login": null,
Expand Down
26 changes: 26 additions & 0 deletions directory/block_producer/domain/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,29 @@ def do(self, user_email, block_producer_id):
raise BlockProducerWithSpecifiedIdentifierDoesNotExistError

return self.block_producer.delete_(identifier=block_producer_id)


class RejectedBlockProducerDescription:
"""
Send block producer status description to the email address implementation.
"""

def __init__(self, user, block_producer):
"""
Constructor.
"""
self.user = user
self.block_producer = block_producer

def do(self, email, block_producer_id):
"""
Send block producer status description to the email address.
"""
if not self.user.does_exist_by_email(email=email):
raise UserWithSpecifiedEmailAddressDoesNotExistError

if not self.block_producer.does_exist(identifier=block_producer_id):
raise BlockProducerWithSpecifiedIdentifierDoesNotExistError

status_description = self.block_producer.get_status_description(email=email, identifier=block_producer_id)
return status_description
1 change: 1 addition & 0 deletions directory/block_producer/dto/block_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BlockProducerDto:
full_description: str = ''
logo_url: str = ''
status: str = ''
status_description: str = ''

linkedin_url: str = ''
twitter_url: str = ''
Expand Down
2 changes: 2 additions & 0 deletions directory/block_producer/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BlockProducerCollection,
BlockProducerSearchCollection,
BlockProducerSingle,
RejectedBlockProducerDescriptionSingle,
)
from block_producer.views.comment import (
BlockProducerCommentCollection,
Expand All @@ -27,4 +28,5 @@
path('likes/numbers/', BlockProducerLikeNumberCollection.as_view()),
path('<int:block_producer_id>/likes/', BlockProducerLikeCollection.as_view()),
path('<int:block_producer_id>/avatars/', BlockProducerAvatarSingle.as_view()),
path('<int:block_producer_id>/description/', RejectedBlockProducerDescriptionSingle.as_view()),
]
4 changes: 4 additions & 0 deletions directory/block_producer/fixtures/block_producer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"full_description": "# About Us\n\nFounded by a team of serial tech entrepreneurs, block producer Canada is headquartered in Montreal, Canada and is backed by reputable Canadian financial players. We believe that BP.IO will fundamentally change our economic and social systems and as such we are deeply committed to contribute to the growth of the ecosystem.",
"logo_url": "https://block-producers-directory.s3-us-west-2.amazonaws.com/bps/logos/default-block-producer-logotype.png",
"status": "active",
"status_description": "Okay.",
"created_at": "2019-06-01T13:19:37+00:00",
"linkedin_url": "https://www.linkedin.com/in/bpcanada",
"twitter_url": "https://twitter.com/bpcanada",
Expand All @@ -36,6 +37,7 @@
"full_description": "# About Us\n\nFounded by a team of serial tech entrepreneurs, block producer Canada is headquartered in Montreal, Canada and is backed by reputable Canadian financial players. We believe that BP.IO will fundamentally change our economic and social systems and as such we are deeply committed to contribute to the growth of the ecosystem.",
"logo_url": "https://block-producers-directory.s3-us-west-2.amazonaws.com/bps/logos/default-block-producer-logotype.png",
"status": "active",
"status_description": "Okay.",
"created_at": "2019-06-02T13:19:37+00:00",
"linkedin_url": "https://www.linkedin.com/in/bpcanada",
"twitter_url": "https://twitter.com/bpcanada",
Expand All @@ -61,6 +63,7 @@
"full_description": "# About Us\n\nFounded by a team of serial tech entrepreneurs, block producer USA is headquartered in San Francisco, USA and is backed by reputable American financial players. We believe that BP.IO will fundamentally change our economic and social systems and as such we are deeply committed to contribute to the growth of the ecosystem.",
"logo_url": "https://block-producers-directory.s3-us-west-2.amazonaws.com/bps/logos/default-block-producer-logotype.png",
"status": "active",
"status_description": "Okay.",
"created_at": "2019-06-03T13:19:37+00:00",
"linkedin_url": "https://www.linkedin.com/in/bpusa",
"twitter_url": "https://twitter.com/bpusa",
Expand All @@ -86,6 +89,7 @@
"full_description": "# About Us\n\nFounded by a team of serial tech entrepreneurs, block producer Canada is headquartered in Montreal, Canada and is backed by reputable Canadian financial players. We believe that BP.IO will fundamentally change our economic and social systems and as such we are deeply committed to contribute to the growth of the ecosystem.",
"logo_url": "https://block-producers-directory.s3-us-west-2.amazonaws.com/bps/logos/default-block-producer-logotype.png",
"status": "active",
"status_description": "Okay.",
"created_at": "2019-06-04T13:19:37+00:00",
"linkedin_url": "https://www.linkedin.com/in/bpcanada",
"twitter_url": "https://twitter.com/bpcanada",
Expand Down
9 changes: 9 additions & 0 deletions directory/block_producer/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,12 @@ class UploadBlockProducerAvatarForm(forms.Form):

title = forms.CharField(max_length=150)
file = forms.FileField()


class RejectedBlockProducerDescriptionForm(forms.Form): # noqa: D205, D400
"""
Send a message to the specified email address with a description
of the reason why the block producer has been rejected form implementation.
"""

email = forms.EmailField()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.5 on 2019-09-27 15:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('block_producer', '0006_add_created_at'),
]

operations = [
migrations.AddField(
model_name='blockproducer',
name='status_description',
field=models.TextField(blank=True, max_length=1000),
),
migrations.AlterField(
model_name='blockproducer',
name='full_description',
field=models.TextField(blank=True, max_length=10000),
),
]
12 changes: 11 additions & 1 deletion directory/block_producer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class BlockProducer(models.Model):
website_url = models.URLField(max_length=200, blank=False)
location = models.CharField(max_length=100, blank=True)
short_description = models.CharField(max_length=100, blank=False)
full_description = models.TextField(blank=True)
full_description = models.TextField(max_length=10000, blank=True)
logo_url = models.URLField(max_length=200, blank=True, default=settings.DEFAULT_BLOCK_PRODUCER_LOGOTYPE_URL)

status = models.CharField(max_length=10, choices=BLOCK_PRODUCER_STATUSES, default=BLOCK_PRODUCER_STATUS_MODERATION)
status_description = models.TextField(max_length=1000, blank=True)
created_at = models.DateTimeField(auto_now_add=True)

linkedin_url = models.URLField(max_length=200, blank=True)
Expand Down Expand Up @@ -195,6 +196,15 @@ def delete_(cls, identifier):
"""
cls.objects.filter(id=identifier).delete()

@classmethod
def get_status_description(cls, email, identifier):
"""
Get block producer status description by its identifier.
"""
block_producer_as_dict = cls.objects.filter(user__email=email, id=identifier).values().first()

return block_producer_as_dict.get('status_description')


class BlockProducerLike(models.Model):
"""
Expand Down
Loading

0 comments on commit 656f533

Please sign in to comment.