utils.py

About this file

It handles the user-request utilities to:

Add user-request,
Edit user-request,
Remove user-request,
Create user-request event,
Create user-request event object,
Get the current point of contact of a given request,
Toggles point of contact of a given request,
Check if a given request has a point of contact,
Remove the current point of contact from a given request,
Determine point of contact of change.

Code Issues

  • For the functions edit_user_request and remove_user_request, a temporary variable tmp on lines 130, 145, 191, and 204, is being used to store the return value of sending an email. However, that variable is not being used elsewhere after storing the return value. Recommend removing that temporary variable if that return value of sending an email will not be used.

Code Check Report


app/user_request/utils.py:27:121: E501 line too long (121 > 120 characters)
app/user_request/utils.py:144:5: F841 local variable 'tmp' is assigned to but never used
app/user_request/utils.py:202:5: F841 local variable 'tmp' is assigned to but never used
app/user_request/utils.py:335:121: E501 line too long (175 > 120 characters)
                        

Documentation drawn from source code


add_user_request(request_id, user_guid, permissions, point_of_contact):

Create a users permissions entry for a request and notify all agency administrators and the user that the permissions
have changed.

:param request_id: FOIL request ID
:param user_guid: string guid of the user being edited
:param permissions: Updated permissions values {'permission': true}
:param point_of_contact: boolean value to set user as point of contact or not

edit_user_request(request_id, user_guid, permissions, point_of_contact):

Edit a users permissions on a request and notify all agency administrators and the user that the permissions
have changed.

:param request_id: FOIL request ID
:param user_guid: string guid of the user being edited
:param permissions: Updated permissions values {'permission': true}
:param point_of_contact: boolean value to set user as point of contact or not

remove_user_request(request_id, user_guid):

Remove user from request and sends email to all agency administrators and to user being removed.
Delete row from UserRequests table and stores event object into Events.

:param request_id: FOIL request ID
:param user_guid: string guid of user being removed


create_user_request_event(events_type, user_request, old_permissions=None, old_point_of_contact=None,

Create an Event for the addition, removal, or updating of a UserRequest and insert into the database.

Args:
events_type (str): event type from the constants defined in constants.event_type.
user_request (UserRequests): UserRequests object.
old_permissions (int): Value of permissions for the request.
user (Users): Users object that represents the user being modified.

Returns:
Events: The event object representing the change made to the user.


create_user_request_event_object(events_type, user_request, old_permissions=None, old_point_of_contact=None,

Create an Event for the addition, removal, or updating of a UserRequest and insert into the database.

Args:
events_type (str): event type from the constants defined in constants.event_type.
user_request (UserRequests): UserRequests object.
old_permissions (int): Value of permissions for the request.
user (Users): Users object that represents the user performing the user_request modification

Returns:
Events: The event object representing the change made to the user.


get_current_point_of_contact(request_id):

Get the current point of contact of a given request
:param request_id: FOIL request ID
:return: UserRequest object of the current point of contact

set_point_of_contact(request_id, user_request, point_of_contact):

Toggles point of contact of a given request
:param request_id: FOIL request ID
:param user_request: UserRequest row to be changed
:param point_of_contact: boolean flag for point of contact

has_point_of_contact(request_id):

Check if a given request has a point of contact
:param request_id: FOIL request ID
:return: True if there is a current point of contact, False otherwise

remove_point_of_contact(request_id):

Remove the current point of contact from a given request
:param request_id: FOIL request ID

determine_point_of_contact_change(request_id, user_request, point_of_contact):

Determines what action needs to be done to the point of contact
:param request_id: FOIL request ID
:param user_request: UserRequest row to be changed
:param point_of_contact: boolean flag for point of contact

Source code