-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CTHUB 198 - save/update users (#218)
* chore: -backend: updates users moved into new service -frontend: adds immer for setting state, uses original users array rather than creating new one * chore: moves transaction.atomic to service
- Loading branch information
Showing
10 changed files
with
185 additions
and
59 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
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,13 @@ | ||
from api.models.user import User | ||
from api.models.user_permission import UserPermission | ||
from api.models.permission import Permission | ||
|
||
def create_permission_list(user): | ||
user = User.objects.filter(idir=user).first() | ||
user_permission = UserPermission.objects.filter(user_id=user.id) | ||
permissions = [] | ||
if user_permission: | ||
for each in user_permission: | ||
permission = Permission.objects.get(id=each.permission_id) | ||
permissions.append(permission.description) | ||
return permissions |
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 @@ | ||
from django.db import transaction | ||
from api.models.user_permission import UserPermission | ||
from api.models.permission import Permission | ||
from api.models.user import User | ||
|
||
@transaction.atomic | ||
def update_permissions(self, request): | ||
msg = [] | ||
permissions = Permission.objects.all() | ||
UserPermission.objects.all().delete() | ||
for each in request.data: | ||
for k, v in each.items(): | ||
if k == 'idir': | ||
user = User.objects.get(idir=v) | ||
if k == 'user_permissions': | ||
for permission_description, value in v.items(): | ||
if value == True or (user.idir == request.user and permission_description == 'admin'): | ||
## if they are updating permissions then they are already admin user, they cannot remove their own admin | ||
permission = permissions.get(description=permission_description) | ||
try: | ||
UserPermission.objects.create(user_id=user.id, permission_id=permission.id) | ||
except Exception as error: | ||
msg.append("{} permission could not be added to {}".format(permission_description, user.idir)) |
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
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
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