-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f68bb2
commit 893b762
Showing
10 changed files
with
309 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
meta { | ||
name: Assets Links | ||
type: http | ||
seq: 1 | ||
} | ||
|
||
get { | ||
url: {{URL}}/.well-known/assetlinks.json | ||
body: none | ||
auth: none | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
meta { | ||
name: Fetch Account | ||
type: http | ||
seq: 1 | ||
} | ||
|
||
get { | ||
url: {{URL}}/api/v1/fetch/ | ||
body: json | ||
auth: none | ||
} | ||
|
||
headers { | ||
Authorization: Token {{token}} | ||
} | ||
|
||
body:json { | ||
{ | ||
"uuid": "", | ||
"cif": "" , | ||
"email": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
meta { | ||
name: Preregister Consumer | ||
type: http | ||
seq: 3 | ||
} | ||
|
||
post { | ||
url: {{URL}}/api/v1/preregister/ | ||
body: json | ||
auth: none | ||
} | ||
|
||
headers { | ||
Authorization: Token {{token}} | ||
} | ||
|
||
body:json { | ||
{ | ||
"person": { | ||
"cif": "1234567A", | ||
"member_id": "1234", | ||
"name": "Prueba", | ||
"surname": "Consumidora", | ||
"email": "", | ||
"contact_phone": "123123456", | ||
"address": "Calle falsa 123", | ||
"city": "MAD" | ||
}, | ||
"email": "" | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
meta { | ||
name: Preregister Intercoop | ||
type: http | ||
seq: 4 | ||
} | ||
|
||
post { | ||
url: {{URL}}/api/v1/preregister/ | ||
body: json | ||
auth: none | ||
} | ||
|
||
headers { | ||
Authorization: Token {{token}} | ||
} | ||
|
||
body:json { | ||
{ | ||
"person": { | ||
"cif": "1234567A", | ||
"member_id": "1234", | ||
"name": "Prueba", | ||
"surname": "Intercoop", | ||
"email": "", | ||
"contact_phone": "123123456", | ||
"address": "Calle falsa 123", | ||
"city": "MAD", | ||
"is_intercoop": true | ||
}, | ||
"email": "" | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
meta { | ||
name: Preregister Provider | ||
type: http | ||
seq: 2 | ||
} | ||
|
||
post { | ||
url: {{URL}}/api/v1/preregister/ | ||
body: json | ||
auth: none | ||
} | ||
|
||
headers { | ||
Authorization: Token {{token}} | ||
} | ||
|
||
body:json { | ||
{ | ||
"entity": { | ||
"cif": "1234567A", | ||
"name": "Entidad falsa", | ||
"member_id": "1234", | ||
"description": "Entidad falsa descripción larga", | ||
"short_description": "Entidad falsa descripción corta", | ||
"email": "", | ||
"contact_phone": "123123456", | ||
"address": "Calle falsa 123", | ||
"city" : "MAD", | ||
"latitude": 0, | ||
"longitude": 0, | ||
"legal_form": "cooperativa", | ||
"num_workers": 1, | ||
"telegram_link": "www.telegram.com", | ||
"twitter_link": "www.twitter.com", | ||
"webpage_link": "app.mercadosocial.net", | ||
"facebook_link": "https://www.facebook.com", | ||
"instagram_link": "https://www.instagram.com", | ||
"categories": ["97924fef-a60a-4c9e-adc1-0ce35e0dd8b9", "83d97ae0-538e-43d5-908e-d30b77c4405a"] | ||
}, | ||
"email": "" | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from rest_framework import serializers | ||
|
||
from authentication.models import User | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = User | ||
exclude = ["id", "password", "is_staff", "is_superuser"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
|
||
from django.core.exceptions import MultipleObjectsReturned | ||
from django.http import HttpResponse, HttpResponseNotFound, JsonResponse, HttpResponseForbidden | ||
from rest_framework import authentication, status | ||
from rest_framework.permissions import IsAuthenticated, IsAdminUser | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from api.serializers.consumer import ConsumerSerializer | ||
from api.serializers.provider import ProviderSerializer | ||
from api.serializers.user import UserSerializer | ||
from authentication.models import User | ||
from authentication.models.api_token import APIToken | ||
from authentication.models.preregister import PreRegisteredUser | ||
from market.management.commands.import_madrid_data import set_social_profiles, set_categories | ||
from market.models import Account, Provider, Consumer, Category | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class FetchUserView(APIView): | ||
authentication_classes = [authentication.TokenAuthentication] | ||
permission_classes = (IsAuthenticated, IsAdminUser) | ||
|
||
def get(self, request, format=None): | ||
|
||
|
||
data = request.data | ||
|
||
instance = None | ||
if 'uuid' in data: | ||
instance = Account.objects.get(id=data['uuid']) | ||
if instance is None and 'cif' in data and data['cif'] is not None: | ||
try: | ||
instance = Account.objects.get(cif=data['cif']) | ||
except MultipleObjectsReturned: | ||
raise Exception(f"Duplicated person. CIF: {data['cif']}. ") | ||
if instance is None and 'email' in data and data['email'] is not None: | ||
try: | ||
instance = Account.objects.get(email=data['email']) | ||
except MultipleObjectsReturned: | ||
raise Exception(f"Duplicated person. Email: {data['email']}") | ||
if instance is None: | ||
return HttpResponseNotFound() | ||
|
||
if instance.node != request.user.node: | ||
return HttpResponseForbidden() | ||
|
||
response = {"api_key": APIToken.objects.get_or_create(user=instance.owner)[0].key} | ||
if isinstance(instance, Consumer): | ||
response['type'] = "person" | ||
response['person'] = ConsumerSerializer(instance).data | ||
if (response['person'] is not None) and 'owner' in response['person']: | ||
response['person']['id'] = instance.id | ||
del response["person"]["owner"] | ||
|
||
response['person']['profile_image'] = instance.profile_image.url if instance.profile_image else None | ||
|
||
if response['person']['favorites']: | ||
for i, uuid in enumerate(response['person']['favorites']): | ||
response['person']['favorites'][i] = uuid | ||
elif isinstance(instance, Provider): | ||
response['type'] = "entity" | ||
response['entity'] = ProviderSerializer(instance).data | ||
if (response['entity'] is not None) and 'user' in response['entity']: | ||
response['entity']['id'] = instance.id | ||
if response['entity']['logo']: | ||
response['entity']['logo'] = instance.profile_image.url if instance.profile_image else None | ||
del response['entity']['user'] | ||
del response['entity']['gallery'] | ||
|
||
if instance.categories.count() > 0: | ||
response['entity']['categories'] = [] | ||
for cat in instance.categories.all(): | ||
response['entity']['categories'].append(cat.pk) | ||
|
||
response['user'] = UserSerializer(instance.owner).data | ||
response['user']['is_registered'] = instance.owner.is_registered() | ||
|
||
return Response(data=response, status=status.HTTP_200_OK) | ||
|
||
|
||
class PreRegisterUserView(APIView): | ||
authentication_classes = [authentication.TokenAuthentication] | ||
permission_classes = (IsAuthenticated, IsAdminUser) | ||
|
||
def post(self, request, *args, **kwargs): | ||
data = request.data | ||
|
||
account = None | ||
email = data['email'] | ||
|
||
if not request.user.node: | ||
return HttpResponse(_("Este usuario no gestiona ningún mercado."), status=400) | ||
|
||
if User.objects.filter(email=email).exists(): | ||
return HttpResponse(_("Ya existe un usuario registrado con este correo electrónico."), status=400) | ||
|
||
result = {} | ||
if 'person' in data: | ||
consumer = data['person'] | ||
account = Consumer.objects.create( | ||
node=request.user.node, | ||
cif=consumer.get('cif'), | ||
email=email, | ||
member_id=consumer.get('member_id'), | ||
first_name=consumer.get('name'), | ||
last_name=consumer.get('surname'), | ||
address=consumer.get('address'), | ||
city=consumer.get('city'), | ||
phone_number=consumer.get('contact_phone'), | ||
is_intercoop=consumer.get('is_intercoop', False) | ||
) | ||
result = {"person": {"id": account.id}} | ||
elif 'entity' in data: | ||
provider = data['entity'] | ||
account = Provider.objects.create( | ||
node=request.user.node, | ||
cif=provider.get('cif'), | ||
email=email, | ||
member_id=provider.get('member_id'), | ||
name=provider.get('name'), | ||
address=provider.get('address'), | ||
city=provider.get('city'), | ||
description=provider.get('description'), | ||
short_description=provider.get('short_description'), | ||
latitude=provider.get('latitude', 0), | ||
longitude=provider.get('longitude', 0), | ||
num_workers=provider.get('num_workers', 1), | ||
legal_form=provider.get('legal_form'), | ||
webpage_link=provider.get('webpage_link'), | ||
phone_number=provider.get('contact_phone'), | ||
) | ||
set_social_profiles(provider, account) | ||
set_categories(provider, account) | ||
|
||
result = {"entity": {"id": account.id}} | ||
else: | ||
return HttpResponse(_("No existe objeto entity o person"), status=400) | ||
|
||
PreRegisteredUser.create_user_and_preregister(account) | ||
return JsonResponse(result, status=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters