def add_permissions(user_id: int, permissions: list) -> None: """ Add permissions for user. """ current_permissions = get_permissions(user_id) for value in permissions: if value not in current_permissions: PermissionStore.create(user_id, value) current_permissions += [value]
def del_permissions(user_id: int, permissions: list) -> None: """ Del permissions for user. """ current_permissions = get_permissions(user_id) for value in permissions: if value in current_permissions: permission_list = PermissionStore().read_list( 0, None, user_id, value)[1] PermissionStore().delete(permission_list[0].uid) current_permissions.remove(value)
def get_permissions(user_id: int) -> list: """ Get permissions for user. """ return [ permission.value \ for permission in PermissionStore.read_list(0, None, user_id, None) ]
def wrapper(*args, **kwargs): """ Wrapper function to verify user permission. """ if not current_user.is_authenticated or \ current_user.user is None: logging.debug('Redirect unauthorized (anonymous) user') return redirect(url_for('base.get_home')) permission_value = '%s.%s' % (function.__module__, function.__name__) permissions = PermissionStore.read_list(0, None, current_user.user.id, permission_value) if len(permissions) == 0: return redirect(url_for('base.get_home')) return function(*args, **kwargs)