mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-20 15:31:15 -05:00
For a user to be able to be archived, each service that they are a member of must have at least one other user who is active and who has the 'manage-settings' permission. To archive a user we remove them from all their services and organisations, remove all permissions that they have and change some of their details: - email_address will start with '_archived_<date>' - the current_session_id is changed (to sign them out of their current session) - mobile_number is removed (so we also need to switch their auth type to email_auth) - password is changed to a random password - state is changed to 'inactive' If any of the steps fail, we rollback all changes.
27 lines
659 B
Python
27 lines
659 B
Python
|
|
from app import db
|
|
from app.dao.dao_utils import transactional
|
|
from app.models import ServiceUser, User
|
|
|
|
|
|
def dao_get_service_user(user_id, service_id):
|
|
return ServiceUser.query.filter_by(user_id=user_id, service_id=service_id).one()
|
|
|
|
|
|
def dao_get_active_service_users(service_id):
|
|
query = ServiceUser.query.join(ServiceUser.user).filter(
|
|
ServiceUser.service_id == service_id,
|
|
User.state == 'active'
|
|
)
|
|
|
|
return query.all()
|
|
|
|
|
|
def dao_get_service_users_by_user_id(user_id):
|
|
return ServiceUser.query.filter_by(user_id=user_id).all()
|
|
|
|
|
|
@transactional
|
|
def dao_update_service_user(service_user):
|
|
db.session.add(service_user)
|