users_api package
Subpackages
- users_api.management package
- Subpackages
- users_api.management.commands package
- Submodules
- users_api.management.commands.dataset_groups module
- users_api.management.commands.dataset_mixin module
- users_api.management.commands.datasets_export module
- users_api.management.commands.datasets_restore module
- users_api.management.commands.datasets_show module
- users_api.management.commands.export_base module
- users_api.management.commands.groups_cleanup module
- users_api.management.commands.import_base module
- users_api.management.commands.unlock_user module
- users_api.management.commands.user_create module
- users_api.management.commands.user_set_name module
- users_api.management.commands.user_setpasswd module
- users_api.management.commands.users_add module
- users_api.management.commands.users_export module
- users_api.management.commands.users_group_add module
- users_api.management.commands.users_group_remove module
- users_api.management.commands.users_remove module
- users_api.management.commands.users_restore module
- users_api.management.commands.users_show module
- Module contents
- users_api.management.commands package
- Module contents
- Subpackages
- users_api.migrations package
- users_api.tests package
- Submodules
- users_api.tests.conftest module
- users_api.tests.test_commands module
- users_api.tests.test_commands_datasets module
- users_api.tests.test_federation_credentials_api module
test_create_duplicate_name_federation_credentials()
test_create_federation_credentials_with_authorized_user()
test_create_federation_credentials_with_unauthorized_user()
test_delete_absent_federation_credentials()
test_delete_federation_credentials_with_authorized_user()
test_delete_federation_credentials_with_unauthorized_user()
test_get_federation_credentials_with_authorized_user()
test_get_federation_credentials_with_unauthorized_user()
test_update_federation_credentials_with_authorized_user()
test_update_federation_credentials_with_duplicate_name()
test_update_federation_credentials_with_false_name()
test_update_federation_credentials_with_incorrect_request_data()
test_update_federation_credentials_with_unauthorized_user()
- users_api.tests.test_users_api module
- users_api.tests.test_users_authentication module
expire_email_lockout()
lockout_email()
test_authentication_logging()
test_email_auth_unsuccessful()
test_failed_auth()
test_failed_auth_attempts()
test_failed_auth_lockouts()
test_get_user_info_after_auth()
test_lockout_prevents_login()
test_login_page_template_data()
test_no_password_auth()
test_no_username_auth()
test_password_reset_resets_lockouts()
test_successful_auth()
test_successful_auth_case_insensitive()
test_successful_auth_resets_lockouts()
test_successful_auth_with_next()
- users_api.tests.test_users_groups module
test_adding_admin_group_sets_is_staff()
test_adding_multiple_users_through_admin_group_sets_is_staff()
test_adding_through_admin_group_sets_is_staff()
test_deleting_admin_group_unsets_is_staff()
test_deleting_some_group_does_not_break_is_staff()
test_removing_admin_group_unsets_is_staff()
test_without_admin_group_does_not_have_is_staff()
- users_api.tests.test_users_researcher_registration module
- users_api.tests.test_users_rest module
test_admin_can_add_user_group()
test_admin_can_create_new_user_with_groups()
test_admin_can_create_new_users()
test_admin_can_delete_user()
test_admin_can_get_default_users()
test_admin_can_partial_update_user()
test_admin_can_password_reset()
test_admin_can_remove_user_group()
test_admin_can_reset_user_password()
test_admin_can_see_newly_created_user()
test_admin_can_update_with_new_group()
test_admin_cannot_delete_own_user()
test_admin_cant_partial_update_user_email()
test_admin_password_reset_of_nonexiting_user_fails()
test_admin_sees_all_default_users()
test_all_users_have_groups()
test_new_user_is_not_active()
test_new_user_name_can_be_blank()
test_non_admin_can_not_password_reset()
test_resetting_user_password_does_not_deauthenticates_them()
test_searching_by_email()
test_searching_by_email_finds_only_single_user()
test_searching_by_username()
test_single_admin_cant_remove_superuser_group_from_self()
test_two_admins_can_not_remove_superuser_group_from_self()
test_two_admins_can_remove_superuser_group_from_other()
test_unauthenticated_cant_get_all_users()
test_user_create_email_case_insensitive()
test_user_create_email_case_insensitive_with_groups()
test_user_create_update_case_sensitive_groups()
test_user_name_can_be_updated_to_blank()
test_users_cant_get_all_users()
- users_api.tests.test_users_with_password module
- users_api.tests.test_users_without_password module
- Module contents
Submodules
users_api.forms module
- class users_api.forms.WdaeLoginForm(request: Any = None, **kwargs: Any)[source]
Bases:
Form
A form for users to log in to the system.
- base_fields = {'password': <django.forms.fields.CharField object>, 'username': <django.contrib.auth.forms.UsernameField object>}
- clean() dict [source]
Hook for doing any extra form-wide cleaning after Field.clean() has been called on every field. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field named ‘__all__’.
- declared_fields = {'password': <django.forms.fields.CharField object>, 'username': <django.contrib.auth.forms.UsernameField object>}
- error_messages = {'inactive': 'User is inactive.', 'invalid_credentials': 'Invalid login credentials.', 'no_password': 'Password not provided.', 'no_user': 'User not found.', 'no_username': 'Username not provided.'}
- property media
Return all media required to render the widgets on this form.
- class users_api.forms.WdaePasswordForgottenForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[source]
Bases:
Form
- base_fields = {'email': <django.forms.fields.EmailField object>}
- declared_fields = {'email': <django.forms.fields.EmailField object>}
- property media
Return all media required to render the widgets on this form.
- class users_api.forms.WdaeRegisterPasswordForm(user, *args, **kwargs)[source]
Bases:
WdaeResetPasswordForm
A form for users to set their password when registered in the system.
- base_fields = {'new_password1': <django.forms.fields.CharField object>, 'new_password2': <django.forms.fields.CharField object>}
- declared_fields = {'new_password1': <django.forms.fields.CharField object>, 'new_password2': <django.forms.fields.CharField object>}
- property media
Return all media required to render the widgets on this form.
- class users_api.forms.WdaeResetPasswordForm(user, *args, **kwargs)[source]
Bases:
SetPasswordForm
A form for users to reset their password when forgotten.
- base_fields = {'new_password1': <django.forms.fields.CharField object>, 'new_password2': <django.forms.fields.CharField object>}
- declared_fields = {'new_password1': <django.forms.fields.CharField object>, 'new_password2': <django.forms.fields.CharField object>}
- error_messages = {'password_invalid': 'Your password is either too short (less than 10 symbols) or too weak.', 'password_mismatch': 'The two passwords do not match.'}
- property media
Return all media required to render the widgets on this form.
users_api.models module
- class users_api.models.AuthenticationLog(*args, **kwargs)[source]
Bases:
Model
A model to keep track of all requests for authentication.
Which email was used, when they were made and what number of consecutive failed attempts have been made on this email. The failed attempt counter is reset on a succesful login or a changed password.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- email: EmailField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- failed_attempt: IntegerField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- static get_last_login_for(email: str) AuthenticationLog | None [source]
Get the latest authentication attempt for a specified email.
- get_next_by_time(*, field=<django.db.models.fields.DateTimeField: time>, is_next=True, **kwargs)
- get_previous_by_time(*, field=<django.db.models.fields.DateTimeField: time>, is_next=False, **kwargs)
- static get_remaining_lockout_time(email: str) float [source]
Get the remaining lockout time for a specified email.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- static log_authentication_attempt(email: str, failed: bool) None [source]
Log an attempt for authentication.
- objects = <django.db.models.manager.Manager object>
- time: DateTimeField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class users_api.models.BaseVerificationCode(*args, **kwargs)[source]
Bases:
Model
Base class for temporary codes for verifying the user without login.
- classmethod create(user: WdaeUser) BaseVerificationCode [source]
Create an email verification code.
- created_at: Field
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- classmethod get_code(user: WdaeUser) BaseVerificationCode | None [source]
Get a verification code for a user.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- path: Field
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user: Field
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- user_id
- class users_api.models.GpUserState(*args, **kwargs)[source]
Bases:
Model
Class representing a user’s gene profiles state.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- data: TextField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- user: OneToOneField
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- user_id
- class users_api.models.ResetPasswordCode(*args, **kwargs)[source]
Bases:
BaseVerificationCode
Class used for verification of password resets.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- created_at: Field
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- path: Field
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user: Field
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- user_id
- class users_api.models.SetPasswordCode(*args, **kwargs)[source]
Bases:
BaseVerificationCode
Base class for temporary paths for verifying user without login.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- created_at: Field
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- path: Field
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- user: Field
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- user_id
- class users_api.models.WdaeUser(*args, **kwargs)[source]
Bases:
AbstractBaseUser
,PermissionsMixin
Class representing a user in wdae.
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- REQUIRED_FIELDS = ['name']
- SUPERUSER_GROUP = 'admin'
- UMLIMITED_DOWNLOAD_GROUP = 'unlimited'
- USERNAME_FIELD = 'email'
- property allowed_datasets: list[dict[str, Any]]
- auth_token
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- static change_password(verification_path: SetPasswordCode | ResetPasswordCode, new_password: str) WdaeUser [source]
Initiate password reset for the user.
- date_joined: DateTimeField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- email: EmailField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- email_user(subject: str, message: str, from_email: str | None = None) int [source]
Send an email to the user.
- gpuserstate
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- groups
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings
andTopping.pizzas
areManyToManyDescriptor
instances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- property has_unlimited_download: bool
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_active: BooleanField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_staff: BooleanField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- is_superuser
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- last_login
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name: CharField
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- oauth2_provider_accesstoken
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- oauth2_provider_application
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- oauth2_provider_grant
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- oauth2_provider_idtoken
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- oauth2_provider_refreshtoken
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- objects = <users_api.models.WdaeUserManager object>
- password
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- resetpasswordcode
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- setpasswordcode
Accessor to the related object on the reverse side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is aReverseOneToOneDescriptor
instance.
- user_permissions
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings
andTopping.pizzas
areManyToManyDescriptor
instances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- userquery_set
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- class users_api.models.WdaeUserManager(*args, **kwargs)[source]
Bases:
BaseUserManager
User manager for wdae users.
- create(**kwargs: Any) WdaeUser [source]
Create a new object with the given kwargs, saving it to the database and returning the created object.
- users_api.models.csrf_clear(view_func: Callable) Any [source]
Skips the CSRF checks by setting the ‘csrf_processing_done’ to true.
- users_api.models.group_post_delete(sender: Type[Group], **kwargs: Any) None [source]
Automatically remove staff privileges of SUPERUSER_GROUP users.
Automatically remove staff privileges of users belonging to the SUPERUSER_GROUP group if that group is deleted.
- users_api.models.group_pre_delete(sender: Type[Group], **kwargs: Any) None [source]
Attach user-ids when a group is being deleted.
When deleting a group, attaches the ids of the users who belonged to it in order to be used in the post_delete signal. Used only for the SUPERUSER_GROUP group.
- users_api.models.send_already_existing_email(user: WdaeUser) None [source]
Send an email to already existing user.
- users_api.models.send_reset_email(user: WdaeUser, verif_path: BaseVerificationCode, by_admin: bool = False) None [source]
Return dict with subject and message of the email.
- users_api.models.send_reset_inactive_acc_email(user: WdaeUser) None [source]
Send an email to an inactive user.
- users_api.models.send_verif_email(user: WdaeUser, verif_path: BaseVerificationCode) None [source]
Send a verification email to the user.
users_api.serializers module
- class users_api.serializers.CreatableSlugRelatedField(*args, **kwargs)[source]
Bases:
SlugRelatedField
Try to get and return related field and create it if it does not exist.
Used for the ‘groups’ field in the user serializer - if a new group is given to a user, it will be created and then attached to the user.
- class users_api.serializers.DatasetSerializer(*args, **kwargs)[source]
Bases:
BaseSerializer
Dataset serializer.
- class users_api.serializers.UserSerializer(*args, **kwargs)[source]
Bases:
ModelSerializer
User serializer.
- class Meta[source]
Bases:
object
- fields = ('id', 'email', 'name', 'hasPassword', 'groups', 'allowedDatasets')
- create(validated_data: dict) Any [source]
We have a bit of extra checking around this in order to provide descriptive messages when something goes wrong, but this method is essentially just:
return ExampleModel.objects.create(**validated_data)
If there are many to many fields present on the instance then they cannot be set until the model is instantiated, in which case the implementation is like so:
example_relationship = validated_data.pop(‘example_relationship’) instance = ExampleModel.objects.create(**validated_data) instance.example_relationship = example_relationship return instance
The default implementation also does not handle nested relationships. If you want to support writable nested relationships you’ll need to write an explicit .create() method.
users_api.urls module
users_api.validators module
users_api.views module
- class users_api.views.BasePasswordView(**kwargs)[source]
Bases:
APIView
Base class for set/reset password views.
- code_type: str | None = None
- form: Form | None = None
- template: str | None = None
- verification_code_model: Model | None = None
- class users_api.views.FederationCredentials(**kwargs)[source]
Bases:
APIView
API for handling federation credentials/applications.
- authentication_classes = (<class 'utils.authentication.GPFOAuth2Authentication'>,)
- class users_api.views.RESTLoginView(**kwargs)[source]
Bases:
APIView
View for REST session bases logging in.
- class users_api.views.ResetPassword(**kwargs)[source]
Bases:
BasePasswordView
- code_type: str | None = 'reset'
- form
alias of
WdaeResetPasswordForm
- template: str | None = 'users_api/registration/reset-password.html'
- verification_code_model
alias of
ResetPasswordCode
- class users_api.views.SetPassword(**kwargs)[source]
Bases:
BasePasswordView
- code_type: str | None = 'set'
- form
alias of
WdaeRegisterPasswordForm
- template: str | None = 'users_api/registration/set-password.html'
- verification_code_model
alias of
SetPasswordCode
- class users_api.views.UserGpStateView(**kwargs)[source]
Bases:
APIView
User’s gene profiles state view.
- class users_api.views.UserViewSet(**kwargs)[source]
Bases:
ModelViewSet
API endpoint that allows users to be viewed or edited.
- authentication_classes = [<class 'utils.authentication.SessionAuthenticationWithoutCSRF'>, <class 'utils.authentication.GPFOAuth2Authentication'>]
- basename = None
- create(**kwargs: Any) Any
- description = None
- destroy(**kwargs: Any) Any
- detail = None
- filter_backends = (<class 'rest_framework.filters.SearchFilter'>,)
- get_serializer_class() Type[UserWithoutEmailSerializer] | Type[UserSerializer] [source]
Return the class to use for the serializer. Defaults to using self.serializer_class.
You may want to override this if you need to provide different serializations depending on the incoming request.
(Eg. admins get full serialization, others get basic serialization)
- name = None
- partial_update(**kwargs: Any) Any
- permission_classes = (<class 'rest_framework.permissions.IsAdminUser'>,)
- queryset = <QuerySet [<WdaeUser: admin@iossifovlab.com>]>
- search_fields = ('email', 'name', 'groups__name')
- serializer_class
alias of
UserSerializer
- streaming_search(request: Request) StreamingHttpResponse [source]
Search for users and stream the results.
- suffix = None
- update(**kwargs: Any) Any
- users_api.views.check_verif_code(request, *args, **kwargs)[source]
Check if a verification code is valid.
- users_api.views.get_user_info(request, *args, **kwargs)[source]
Get user info for currently logged-in user.