def isAdmin(cn): if sbserver.playerPrivilege(cn) == 2: return True try: return isUserAdmin(player(cn).user.id) except AttributeError, ValueError: return False
def render_user_JSON(self, request, user): return json.dumps({'user': { 'id': user.id, 'privileges': { 'master': isUserMaster(user.id), 'admin': isUserAdmin(user.id) } }})
def render_user_JSON(self, request, user): return json.dumps({ 'user': { 'id': user.id, 'privileges': { 'master': isUserMaster(user.id), 'admin': isUserAdmin(user.id) } } })
def userPrivSetCmd(cn, tcn, args): user_id = player(tcn).user.id if args == 'user': try: if isUser(player(tcn).user.id): sbserver.playerMessage(cn, error('%s already has user permissions.' % sbserver.playerName(tcn))) return except (ValueError, AttributeError): pass else: try: user = loggedInAs(tcn) except AttributeError: sbserver.playerMessage(cn, error('%s is not logged in.' % sbserver.playerName(tcn))) else: dbmanager.query(UserPrivilege).filter(UserPrivilege.user_id==user_id).update({ 'privilege': None }) session.add(UserPrivilege(0, user.id)) session.commit() sbserver.playerMessage(cn, info('User privilege has been given to %s (%s)' % (sbserver.playerName(tcn), user.email))) elif args == 'master': try: if isUserMaster(player(tcn).user.id): sbserver.playerMessage(cn, error('%s already has master permissions.' % sbserver.playerName(tcn))) return except (ValueError, AttributeError): pass else: try: user = loggedInAs(tcn) except AttributeError: sbserver.playerMessage(cn, error('%s is not logged in.' % sbserver.playerName(tcn))) else: dbmanager.query(UserPrivilege).filter(UserPrivilege.user_id==user_id).update({ 'privilege': None }) session.add(UserPrivilege(1, user.id)) session.commit() sbserver.playerMessage(cn, info('Master privilege has been given to %s (%s)' % (sbserver.playerName(tcn), user.email))) elif args == 'admin': try: if isUserAdmin(player(tcn).user.id): sbserver.playerMessage(cn, error('%s already has admin permissions.' % sbserver.playerName(tcn))) return except (ValueError, AttributeError): pass else: try: user = loggedInAs(tcn) except AttributeError: sbserver.playerMessage(cn, error('%s is not logged in.' % sbserver.playerName(tcn))) else: dbmanager.query(UserPrivilege).filter(UserPrivilege.user_id==user_id).update({ 'privilege': None }) session.add(UserPrivilege(2, user.id)) session.commit() sbserver.playerMessage(cn, info('Admin privilege has been given to %s (%s)' % (sbserver.playerName(tcn), user.email))) else: sbserver.playerMessage(cn, error('Privilege level must be \'master\' to set master permissions and \'admin\' to set master or admin permissions'))