-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow user verification through API request #7280
Conversation
app/api/users.py
Outdated
@@ -284,6 +289,12 @@ def before_update_object(self, user, data, view_kwargs): | |||
{'source': ''}, "You are not authorized to update this information." | |||
) | |||
|
|||
if not has_access('is_admin') and data.get('is_verified') is not None: | |||
raise ForbiddenError( | |||
{'pointer': '/data/attributes/is_verified'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
app/api/users.py
Outdated
@@ -67,6 +67,11 @@ def before_create_object(self, data, view_kwargs): | |||
{'pointer': '/data/attributes/email'}, "Email already exists" | |||
) | |||
|
|||
if data.get('is_verified') is not None: | |||
raise UnprocessableEntityError( | |||
{'pointer': '/data/attributes/is_verified'}, "You are not allowed to submit this field" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (103 > 90 characters)
Codecov Report
@@ Coverage Diff @@
## development #7280 +/- ##
===============================================
- Coverage 63.56% 63.54% -0.02%
===============================================
Files 259 259
Lines 13038 13042 +4
===============================================
Hits 8288 8288
- Misses 4750 4754 +4
Continue to review full report at Codecov.
|
app/api/users.py
Outdated
@@ -67,6 +67,11 @@ def before_create_object(self, data, view_kwargs): | |||
{'pointer': '/data/attributes/email'}, "Email already exists" | |||
) | |||
|
|||
if data.get('is_verified') is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be false and should still work
app/api/users.py
Outdated
@@ -284,6 +289,12 @@ def before_update_object(self, user, data, view_kwargs): | |||
{'source': ''}, "You are not authorized to update this information." | |||
) | |||
|
|||
if not has_access('is_admin') and data.get('is_verified') is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is same as previous state, it should still work
app/api/users.py
Outdated
@@ -289,9 +290,9 @@ def before_update_object(self, user, data, view_kwargs): | |||
{'source': ''}, "You are not authorized to update this information." | |||
) | |||
|
|||
if not has_access('is_admin') and data.get('is_verified') is not None: | |||
if not has_access('is_admin') and data.get('is_verified') != user.is_verified: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a user did not submit is_verified
, this will throw. This should only throw when user submits is_verified
and it is different from current one
app/api/users.py
Outdated
not has_access('is_admin') | ||
and data.get('is_verified') is not None | ||
and data.get('is_verified') != user.is_verified | ||
): | ||
raise ForbiddenError( | ||
{'pointer': '/data/attributes/is_verified'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{'pointer': '/data/attributes/is_verified'}, | |
{'pointer': '/data/attributes/is-verified'}, |
app/api/users.py
Outdated
@@ -67,6 +67,12 @@ def before_create_object(self, data, view_kwargs): | |||
{'pointer': '/data/attributes/email'}, "Email already exists" | |||
) | |||
|
|||
if data.get('is_verified'): | |||
raise UnprocessableEntityError( | |||
{'pointer': '/data/attributes/is_verified'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{'pointer': '/data/attributes/is_verified'}, | |
{'pointer': '/data/attributes/is-verified'}, |
@@ -284,6 +290,16 @@ def before_update_object(self, user, data, view_kwargs): | |||
{'source': ''}, "You are not authorized to update this information." | |||
) | |||
|
|||
if ( | |||
not has_access('is_admin') | |||
and data.get('is_verified') is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, there is one catch left. If the user is not admin, and they sent None
, what will happen. Please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #7278
Short description of what this resolves:
Allows admins to verify users through API request
Changes proposed in this pull request:
Checklist
development
branch.