Skip to content

Commit

Permalink
#26 - repair mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Dobbelaere committed Nov 28, 2023
1 parent 4309f2a commit 19d21e3
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
6 changes: 2 additions & 4 deletions OneSila/core/factories/multi_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ def __init__(self, user):
self.user = user

def disable_user(self):
self.user.is_active = False
self.user.save()
self.user.set_inactive()

def send_signal(self):
disabled.send(sender=self.user.__class__, instance=self.user)
Expand All @@ -134,8 +133,7 @@ def __init__(self, user):
self.user = user

def enable_user(self):
self.user.is_active = True
self.user.save()
self.user.set_active()

def send_signal(self):
enabled.send(sender=self.user.__class__, instance=self.user)
Expand Down
12 changes: 12 additions & 0 deletions OneSila/core/models/multi_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ def save(self, *args, **kwargs):

super().save(*args, **kwargs)

def set_active(self, save=True):
self.is_active = True

if save:
self.save()

def set_inactive(self, save=True):
self.is_active = False

if save:
self.save()

class Meta:
verbose_name = _("Multi tenant user")
verbose_name_plural = _("Multi tenant users")
Expand Down
4 changes: 2 additions & 2 deletions OneSila/core/schema/multi_tenant/mutations/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def accept_user_invitation():

def disable_user():
extensions = default_extensions
return EnableUserMutation(MultiTenantUserStatusInput, extensions=extensions)
return DisableUserMutation(MultiTenantUserStatusInput, extensions=extensions)


def enable_user():
extensions = default_extensions
return DisableUserMutation(MultiTenantUserStatusInput, extensions=extensions)
return EnableUserMutation(MultiTenantUserStatusInput, extensions=extensions)
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ class AcceptInvitationMutation(DjangoUpdateMutation):
def update(self, info: Info, instance: models.Model, data: dict[str, Any]):
# Do not optimize anything while retrieving the object to update
with DjangoOptimizerExtension.disabled():
_, user_id = from_base64(data['id'])
user = instance.filter(id=user_id)
fac = AcceptUserInviteFactory(
user=user,
user=instance,
password=data['password'],
language=data['language'])
fac.run()
Expand Down Expand Up @@ -170,4 +168,6 @@ def update(self, info: Info, instance: models.Model, data: dict[str, Any]):
with DjangoOptimizerExtension.disabled():
fac = EnableUserFactory(user=instance)
fac.run()
return fac.user

instance.refresh_from_db()
return instance
2 changes: 1 addition & 1 deletion OneSila/core/schema/multi_tenant/types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@type(MultiTenantUser, filters=MultiTenantUserOrder, order=MultiTenantUserFilter, pagination=True, fields='__all__')
class MultiTenantUserType:
class MultiTenantUserType(relay.Node):
pass


Expand Down
11 changes: 7 additions & 4 deletions OneSila/core/tests/tests_schemas/tests_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ def test_invite_user(self):
variables={'username': username, 'password': "SomePaddk@2k2", "id": user_id}
)

print(resp)

self.assertTrue(resp.errors is None)
self.assertTrue(resp.data['acceptUserInvitation']['isActive'])
self.assertTrue(resp.data['acceptUserInvitation']['invitationAccepted'])
Expand Down Expand Up @@ -229,7 +227,7 @@ def test_enable_disable_user(self):
)

self.assertTrue(resp.errors is None)
self.assertTrue(resp.data['inviteUser']['isActive'])
self.assertTrue(resp.data['enableUser']['isActive'])

disable_query = """
mutation disableUser($id: GlobalID!){
Expand All @@ -240,5 +238,10 @@ def test_enable_disable_user(self):
}
"""

resp = self.stawberry_test_client(
query=disable_query,
variables={"id": user_id}
)

self.assertTrue(resp.errors is None)
self.assertFalse(resp.data['inviteUser']['isActive'])
self.assertFalse(resp.data['disableUser']['isActive'])

0 comments on commit 19d21e3

Please sign in to comment.