Skip to content

Commit

Permalink
Merge pull request #129 from aalhendi/master
Browse files Browse the repository at this point in the history
Fix UpdateAccount to accept optional arguments for partial updates
  • Loading branch information
ulgens authored Jun 17, 2022
2 parents ec3d115 + e0a0734 commit face76b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions graphql_auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class Meta:
fields = flat_dict(app_settings.UPDATE_MUTATION_FIELDS)
field_classes = {"username": CustomUsernameField}

def __init__(self, *args, **kwargs):
super(UpdateAccountForm, self).__init__(*args, **kwargs)
for key, field in self.fields.items():
self.fields[key].required = False


class PasswordLessRegisterForm(UserCreationForm):
"""
Expand Down
4 changes: 4 additions & 0 deletions graphql_auth/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ class UpdateAccountMixin(Output):
@verification_required
def resolve_mutation(cls, root, info, **kwargs):
user = info.context.user
fields = cls.form.Meta.fields
for field in fields:
if field not in kwargs:
kwargs[field] = getattr(user, field)
f = cls.form(kwargs, instance=user)
if f.is_valid():
f.save()
Expand Down
7 changes: 6 additions & 1 deletion graphql_auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.core.signing import BadSignature

from .exceptions import TokenScopeError

warnings.simplefilter("once")


Expand All @@ -28,7 +29,11 @@ def get_token_payload(token, action, exp=None):


def get_token_paylod(token, action, exp=None):
warnings.warn("get_token_paylod is deprecated, use get_token_payload instead", DeprecationWarning, stacklevel=2)
warnings.warn(
"get_token_paylod is deprecated, use get_token_payload instead",
DeprecationWarning,
stacklevel=2,
)
return get_token_payload(token, action, exp)


Expand Down

0 comments on commit face76b

Please sign in to comment.