swh.web.alter.utils module#
- class swh.web.alter.utils.Step(url, active, disabled)#
Bases:
tuple
Create new instance of Step(url, active, disabled)
- active#
Alias for field number 1
- disabled#
Alias for field number 2
- url#
Alias for field number 0
- swh.web.alter.utils.get_django_group_emails(group_name: str) list[str] [source]#
Get group_name members email addresses from django auth system.
- Parameters:
group_name – the name of the Group
- Returns:
a list of email addresses
- swh.web.alter.utils.get_keycloak_group_emails(group_name: str) list[str] [source]#
Get the mail alias for group_name.
For now we use email aliases defined in the config file.
- Parameters:
group_name – the name of the Group
- Returns:
a list containing a single email alias for group_name
- swh.web.alter.utils.get_group_emails(group_name: str) list[str] [source]#
Get a list of recipients for group_name.
The method used to fetch the emails depends on the auth backend.
- Parameters:
group_name – the name of the Group
- Returns:
a list of email addresses
- swh.web.alter.utils.SESSION_ALTERATION_IDS = 'alteration_ids'#
Session key to store the alteration ids current user has access to.
- swh.web.alter.utils.SESSION_VERIFIED_EMAIL = 'alteration_email'#
Session key to store an email address validated by the current user.
- swh.web.alter.utils.has_access(request: HttpRequest, pk: UUID) bool [source]#
Check if the current user has access to an Alteration.
- Parameters:
request – an HttpRequest
pk – an Alteration id
- Returns:
True if the user is allowed.
- swh.web.alter.utils.set_access(request: HttpRequest, pk: UUID) None [source]#
Store pk in the user’s session.
- Parameters:
request – an HttpRequest
pk – an Alteration id
- swh.web.alter.utils.set_verified_email(request: HttpRequest, email: str) None [source]#
Store a verified email in the user’s session.
- Parameters:
request – an HttpRequest
email – an email address
- swh.web.alter.utils.verified_email(request: HttpRequest) str [source]#
A validated email for the current user.
Value is set by the assistant_email_verification view.
- Parameters:
request – an HttpRequest
- Returns:
A verified email address or an empty string if no email has been verified or if the verified email has been blocked meanwhile
- swh.web.alter.utils.requestors_restricted(view_func)[source]#
A decorator to protect views from unauthorized access.
Requires a view with a pk keyword argument matching an Alteration id. The wrapper checks if the current user has access it or send a redirect to the alteration_access view.
- swh.web.alter.utils.generate_origin_changelog(old_url: str, old_values: dict[str, Any]) str [source]#
Generate a short changelog after updating an Origin.
- Parameters:
old_url – the original origin url
old_values – the list of changed fields (e.g. Form.changed_data)
- Returns:
A text describing the changes
- swh.web.alter.utils.generate_alteration_changelog(old_values: dict[str, Any]) str [source]#
Generate a short changelog after updating an Alteration.
- Parameters:
old_values – the list of changed fields (e.g. Form.changed_data)
- Returns:
A text describing the changes
- swh.web.alter.utils.generate_changelog(instance: Alteration | Origin, introduction: str, old_values: dict[str, Any]) str [source]#
Generic changelog generator.
- Parameters:
instance – a model instance
introduction – a sentence introducing the changes
old_values – a dict of changed values (field: old value)
- Returns:
A text listing the fields impacted and their previous values
- swh.web.alter.utils.process_state(request) dict[str, Step] [source]#
Describe the alteration request process state.
The alteration request assistant is a multi-step form, where the user is able to go back and forward in the process as long as required data has been filled.
This method builds a dict of each steps as keys (email verification, category chooser, etc.) and step state as values (url, current active step or not, available step or not) using session vars & request path.
- Parameters:
request – an
HttpRequest
- Returns:
The alteration request process state
- swh.web.alter.utils.redirect_to_step(request, current_step: str) HttpResponse | None [source]#
Redirect the user to the proper step.
Prevent a user skipping steps in the process. It redirects the user to the first missing step of the form (ie. you try to access /reasons before choosing a category you are redirected to /category) and displays a message to explain why.
- Parameters:
request – an
HttpRequest
current_step – the name of current step
- Returns:
A redirect to a previous step if some data is missing