mirror of
https://github.com/GSA/notifications-api.git
synced 2026-07-18 05:30:48 -04:00
replace user_schema with serialize method on user model
this is so that we can filter out inactive organisations and services note: can't remove user schema completely, as we still use it in POST /user to create new users
This commit is contained in:
@@ -133,6 +133,38 @@ class User(db.Model):
|
||||
def check_password(self, password):
|
||||
return check_hash(password, self._password)
|
||||
|
||||
def get_permissions(self):
|
||||
from app.dao.permissions_dao import permission_dao
|
||||
retval = {}
|
||||
for x in permission_dao.get_permissions_by_user_id(self.id):
|
||||
service_id = str(x.service_id)
|
||||
if service_id not in retval:
|
||||
retval[service_id] = []
|
||||
retval[service_id].append(x.permission)
|
||||
return retval
|
||||
|
||||
def serialize(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'name': self.name,
|
||||
'email_address': self.email_address,
|
||||
'auth_type': self.auth_type,
|
||||
'current_session_id': self.current_session_id,
|
||||
'failed_login_count': self.failed_login_count,
|
||||
'logged_in_at': self.logged_in_at.strftime(DATETIME_FORMAT) if self.logged_in_at else None,
|
||||
'mobile_number': self.mobile_number,
|
||||
'organisations': [x.id for x in self.organisations if x.active],
|
||||
'password_changed_at': (
|
||||
self.password_changed_at.strftime('%Y-%m-%d %H:%M:%S.%f')
|
||||
if self.password_changed_at
|
||||
else None
|
||||
),
|
||||
'permissions': self.get_permissions(),
|
||||
'platform_admin': self.platform_admin,
|
||||
'services': [x.id for x in self.services if x.active],
|
||||
'state': self.state,
|
||||
}
|
||||
|
||||
|
||||
user_to_service = db.Table(
|
||||
'user_to_service',
|
||||
|
||||
Reference in New Issue
Block a user