def user_profile(token, u_id): """ Obtain user profile. """ database = DataBase() user_profile = database.get_info_from_id(u_id) if not user_profile: raise InputError('User does not exist') return {'user': user_profile}
def admin_userpermission_change(token, u_id, permission_id): """ Change user permissions. """ database = DataBase() user = database.get_info_from_id(u_id) admin = database.get_account_info(token) # Error checking if not user or (permission_id != USER_PERMISSIONS and permission_id != OWNER_PERMISSIONS): raise InputError if admin['permissions'] != OWNER_PERMISSIONS: raise AccessError user['permissions'] = permission_id database.close() return {}
def channel_invite(token, channel_id, u_id): """ Invite registered users to channels. """ # Open database and gather channel info and member info database = DataBase() channel = database.get_channel_info(channel_id) channel_member = database.get_account_info(token) add_member = database.get_info_from_id(u_id) # Error testing if not channel or not add_member: raise InputError('Channel doesn\'t exist or member doesn\'t exist') if channel_member['permissions'] != OWNER_PERMISSIONS: if channel_member['u_id'] not in channel['members_id']: raise AccessError('Not a member in the channel') # Update database channel['members_id'].append(u_id) database.close() return {}