Skip to content

Commit

Permalink
Merge pull request #769 from weni-ai/feature/get-all-company-data
Browse files Browse the repository at this point in the history
return all organization with new user has permission; fix unit test
  • Loading branch information
barbosajackson authored Oct 13, 2023
2 parents c70ac0b + 6eabf2b commit 1a0d819
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
32 changes: 15 additions & 17 deletions connect/api/v1/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,28 @@ def receive_emails(self, request, **kwargs):
)
def get_user_company_info(self, request, **kwargs):
user = self.request.user
authorizations = user.authorizations_user
if authorizations.count() == 1:
organization = authorizations.first().organization
authorizations = user.authorizations_user.all()
response = []

for authorization in authorizations:

organization = authorization.organization
first_user = organization.authorizations.order_by("created_at").first().user

if first_user.id != user.id:
organization = dict(
organization_data = dict(
uuid=str(organization.uuid),
name=organization.name,
authorization=authorizations.first().role
)
company = dict(
company_name=first_user.company_name,
company_segment=first_user.company_segment,
company_sector=first_user.company_sector,
number_people=first_user.number_people,
weni_helps=first_user.weni_helps
authorization=authorization.role
)
data = dict(
organization=organization,
company=company
response.append(
dict(
organization=organization_data,
company=first_user.get_company_data
)
)
return Response(status=status.HTTP_200_OK, data=data)

return Response(status=status.HTTP_200_OK, data={})
return Response(status=status.HTTP_200_OK, data=response)


class SearchUserViewSet(mixins.ListModelMixin, GenericViewSet): # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion connect/api/v1/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ def request(self, token):

def test_okay(self):
response, content_data = self.request(self.user_token)
self.assertEquals(list(content_data.keys()), ['organization', 'company'])
self.assertEquals(list(content_data[0].keys()), ['organization', 'company'])
self.assertEqual(response.status_code, status.HTTP_200_OK)
10 changes: 10 additions & 0 deletions connect/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,16 @@ def set_verify_email(self):

self.save(update_fields=["first_login"])

@property
def get_company_data(self):
return dict(
company_name=self.company_name,
company_segment=self.company_segment,
company_sector=self.company_sector,
number_people=self.number_people,
weni_helps=self.weni_helps
)


class UserEmailSetup(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="email_setup")
Expand Down

0 comments on commit 1a0d819

Please sign in to comment.