Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_event_admin(session, event_name, user_name):
"""Add an administrator event.
Parameters
----------
session : :class:`sqlalchemy.orm.Session`
The session to directly perform the operation on the database.
event_name : str
The event name.
user_name : str
The user name.
"""
event = select_event_by_name(session, event_name)
user = select_user_by_name(session, user_name)
event_admin = select_event_admin_by_instance(session, event, user)
if event_admin is None:
event_admin = EventAdmin(event=event, admin=user)
session.commit()
"""Whether or not a user is administrator or administrate an event.
Parameters
----------
session : :class:`sqlalchemy.orm.Session`
The session to directly perform the operation on the database.
event_name : str
The event name.
user_name : str
The user name.
"""
event = select_event_by_name(session, event_name)
user = select_user_by_name(session, user_name)
if user.access_level == 'admin':
return True
event_admin = select_event_admin_by_instance(session, event, user)
if event_admin is None:
return False
return True
----------
session : :class:`sqlalchemy.orm.Session`
The session to directly perform the operation on the database.
event_name : str
The event name.
user_name : str
The user name.
Returns
-------
event_admin : :class:`ramp_database.model.EventAdmin` or None
The event/admin instance queried.
"""
event = select_event_by_name(session, event_name)
user = select_user_by_name(session, user_name)
return select_event_admin_by_instance(session, event, user)