def deactivate(user_id): u = user_datastore.get_user(int(user_id)) if u is not None: app.logger.debug("Deactivating user %s", u.nickname) user_datastore.deactivate_user(u) db.session.commit() return True return False
def deactivate(user_id): """ Disable access for a user """ user = user_datastore.get_user(int(user_id)) if user is not None: app.logger.debug("Deactivating user %s", user.nickname) user_datastore.deactivate_user(user) db.session.commit() return True return False
def manage_admin_role(cls, uid): user = user_datastore.get_user(int(uid)) role = user_datastore.find_or_create_role("admin", description="Administrator") if role is not None: if role not in user.roles: app.logger.debug("Giving admin privileges to user %s" % (user.nickname)) user_datastore.add_role_to_user(user, role) else: app.logger.debug("Removing admin privileges to user %s" % (user.nickname)) user_datastore.remove_role_from_user(user, role) else: app.logger.error("Cannot find and affect admin role to user") return False db.session.commit() return True
def manage_admin_role(cls, uid): """ Toggle admin roles for given uid """ user = user_datastore.get_user(int(uid)) role = user_datastore.find_or_create_role( "admin", description="Administrator") if role is not None: if role not in user.roles: app.logger.debug("Giving admin privileges to user %s" % (user.nickname)) user_datastore.add_role_to_user(user, role) else: app.logger.debug("Removing admin privileges to user %s" % (user.nickname)) user_datastore.remove_role_from_user(user, role) else: app.logger.error("Cannot find and affect admin role to user") return False db.session.commit() return True
def add_role_to_user(uid, role): user = user_datastore.get_user(int(uid)) user_datastore.add_role_to_user(user, role)