def test_create_outgoing(self): """Create an outgoing record.""" Category.create(category_id='001', description='Testing Stock') Project.create(project_id='001', project_description="Testing") Role.create(role_name='Admin') User.create(first_name='Jay', second_name='Palm', phone='9783978223', role='Admin', username='******', password='******', email='*****@*****.**') create_stock('001', 'Testing stock', 1, '001', 9.99) create_outgoing_stock(stock='001', project_id='001', date="2015-07-22", quantity='7', username='******') OutgoingStock.get(OutgoingStock.stock == '001').delete_instance() Stock.get(Stock.category == '001').delete_instance() User.get(User.username == 'JayPalm').delete_instance() Role.get(Role.role_name == 'Admin').delete_instance() Project.get(Project.project_id == '001').delete_instance() Category.get(Category.category_id == '001').delete_instance()
def respond_role_menu(call, user): role = Role.get(Role.role_name == call.data) prev_value = RoleSelectionTracker.get( RoleSelectionTracker.user == user, RoleSelectionTracker.role == role).checked new_value = not prev_value RoleSelectionTracker.update(checked=new_value).where( RoleSelectionTracker.user == user, RoleSelectionTracker.role == role).execute() if new_value: answer_callback(f"نقش {role.role_name} اضافه شد.", call.id) else: answer_callback(f"نقش {role.role_name} حذف شد.", call.id) # update role team keyboard if role.team == "مافیا": message_id = Tracker.get(Tracker.id == user.id).mafia_message_id else: message_id = Tracker.get(Tracker.id == user.id).citizen_message_id # edit reply keyboard with new values edit_message_reply_markup( create_role_selection_menu(user, role.team), chat_id=user.id, message_id=message_id, ) # send the new list of roles to every player players = get_players(user, include_god=True) num_players = len(players) - 1 for player in players: send_current_roles(player, num_players, edit=True)
def host_send_roles(message, user): players = get_players(user) roles = get_selected_roles(user) if len(players) > len(roles): send_message(user.id, ":cross_mark: " f"تعداد بازیکنها بیشتر از نقشهاست.") return if len(players) < len(roles): send_message(user.id, ":cross_mark: " f"تعداد بازیکنها کمتر از نقشهاست.") return # shuffle players and send their roles. players_id = [player.user.id for player in players] random.shuffle(roles) for role_name, player_id in zip(roles, players_id): role_db = Role.get(Role.role_name == role_name) text = f":bust_in_silhouette: نقش شما: <b>{role_name}</b>\n" text += f":high_voltage: تیم: <b>{role_db.team}</b>\n\n" text += ":page_facing_up: <b>شرح نقش:</b>\n" text += role_db.description send_message(player_id, text) Game.update(mafia_role=role_name).where(Game.id == player_id).execute() # get updated players (mafia_role is updated now) players = get_players(user) # send roles to GOD send_message(user.id, get_players_roles(players))
def delete(self, id): role = Role.get(id) if role: role.delete() return '', 204 else: abort(404, error='Role not exist.')
def wrapper(*args, **kwargs): if app.current_user is not None: r = Role.get(Role.role == role) if app.current_user.role.level >= r.level: return func(*args, **kwargs) app.flash(u'У Вас недостатньо прав для перегляду') redirect() app.flash(u'Увійдіть, щоб переглянути дану сторінку') redirect('/login?back=' + request.path)
async def remove_role(message): splitmsg = message.content.split() rolename = ' '.join(splitmsg[1:]) role = discord.utils.get(message.server.roles, name=rolename) try: r = Role.get(Role.rid == role.id) r.assignable = False r.save() except Role.DoesNotExist as e: return await reply(f"The {rolename} role is now assignable", message)
async def remove_leader_role(message): splitmsg = message.content.split() rolename = ' '.join(splitmsg[1:]) role = discord.utils.get(message.server.roles, name=rolename) try: r = Role.get(Role.rid == role.id) r.leaderboard = False r.save() except Role.DoesNotExist as e: return await reply( f"The {rolename} role will no longer given as a leaderboard reward", message)
async def iamnot(message): splitmsg = message.content.split() rolename = ' '.join(splitmsg[1:]) role = None for ro in message.server.roles: if ro.name.lower() == rolename.lower(): role = ro try: r = Role.get(Role.rid == role.id) if r.assignable: await client.remove_roles(message.author, role) except Role.DoesNotExist as e: return await reply(f"I have removed the {rolename} role from you", message)
def check(action: int, resource: Resource): """ Function to check the user access for a particular action on resource :return: bool """ logged_in_user = User.get( filters={'username': UserLogin.check_session().username})[0] user_roles = Role.get(filters={'id': logged_in_user.roles}) policies = [] for role in user_roles: policies.extend(role.policies) user_policies = Policy.get(filters={'id': policies}) resource_policies = [ policy for policy in user_policies if policy.resource == '*' or policy.resource == resource ] # check for the denied policy denied_policy = next( (policy for policy in resource_policies if policy.effect == 'deny' and ( policy.action == '*' or policy.action == action)), None) if denied_policy: return False # check for an allowed policy allowed_policy = next( (policy for policy in resource_policies if policy.effect == 'allow' and ( policy.action == '*' or policy.action == action)), None) if allowed_policy: return True return False
async def on_message(message): lmsg = None smsg = None if not message.author.bot: if message.content.startswith('cb.'): fields = message.content.split() cmd = fields[0].split('.')[1] await bot.call(cmd, message) return async with lock: if not message.author.bot: server, created = Server.get_or_create(sid=message.server.id) user, created = User.get_or_create(uid=message.author.id) local, created = LocalLevel.get_or_create(user=user, server=server) level, exp = await levelup(server.level, server.experience) try: if level > server.level: # Yay, the server leveled up if server.announce_channel: channel = client.get_channel( f'{server.announce_channel}') smsg = await client.send_message( channel, f"{party} {message.server.name} is now level" f" {level}! {party}") except Exception as e: pass server.level = level server.experience = exp server.save() level, exp = await levelup(user.level, user.experience) user.level = level user.experience = exp user.save() level, exp = await levelup(local.level, local.experience) try: if level > local.level: # User leveled up on the server leaders = LocalLevel.select().where( LocalLevel.server == server).order_by( LocalLevel.level.desc(), LocalLevel.experience.desc()).limit(1) if f"{leaders[0].user.uid}" == message.author.id: leaderboard_roles = Role.select().where( (Role.server == server) & (Role.leaderboard == True)).order_by( Role.awardlevel.desc()) leader_role = discord.utils.get( message.server.roles, id=f'{leaderboard_roles[0].rid}') for member in message.server.members: item = next((i for i in member.roles if i.id == f"{leader_role.id}"), None) if item: await client.remove_roles(member, leader_role) await client.add_roles(message.author, leader_role) try: try: role = Role.get((Role.server == server) & (Role.awardlevel == level)) except Role.DoesNotExist as e: role = None if role: r = discord.utils.get(message.server.roles, id=f'{role.rid}') try: logger.info(f"Adding role {r.name} to " f"{message.author.name}") await client.add_roles(message.author, r) except AttributeError as e: logger.exception("Could not add role") except Role.DoesNotExist as e: logger.exception("Count not find level up reward") except Exception as e: logger.exception("Could not process level up") local.level = level local.experience = exp local.save() await asyncio.sleep(10) if lmsg: await client.delete_message(lmsg) if smsg: await client.delete_message(smsg)
view_role_acls = ACL.filter(object_id=view.guid) acl_roles.role_rights = defaultdict(int) for role_acl in view_role_acls: acl_roles.role_rights[role_acl.subject_id] += 1 acl_roles.render() acl_table.objects = [acl_views, acl_roles] #role_rights else: if type == 'role': if len(acl_table.objects) > 2: acl_table.objects = acl_table.objects[:-1] role = Role.get(guid=object_id) acl_table.objects[-1].selected_id = role.guid acl_table.objects[-1].render() selected_view = View.get(guid=acl_table.objects[0].selected_id) acl_rights = ACLRightTemplateCollection() acl_rights.objects = selected_view.rights acl_rights.selected_id = [ acl.right_id for acl in acl_list.values() if acl.object_id == selected_view.guid and acl.subject_id == role.guid ] acl_rights.view_rights = [ acl.right_id for acl in selected_view.acl_list(role) ] acl_rights.render()
from models import Role, Right object_id = request.arguments.get('object_id', '') type = request.arguments.get('type', 'role') # or 'right' command = request.arguments.get('command', 'update') object_instance = Role.get(guid=object_id) if type == 'role' else Right.get(guid=object_id) if object_instance: disabled = '2' if command == 'delete' else '0' form = self.dialog_update.form_update form.title.value = object_instance.name form.title.mode = disabled form.description.value = object_instance.description form.description.mode = disabled form.command.value = command form.object_id.value = object_instance.guid form.workspace_id.value = object_instance.workspace_id self.dialog_update.form_update.btn_update.label = command.title() form.btn_update.action( "setClass", [ 'btn btn-danger' if command == 'delete' else 'btn btn-success' ] ) self.dialog_update.title = '{} {}'.format(type.title(), command.title()) self.dialog_update.show = '1'
def add_role_test(): u = User.from_object(session['user']) role = User_Role.create( role=Role.get(Role.role == AuthRoleType.ADMIN.value), user=u) return redirect(url_for('auth.login'))
def get(self, id): role = Role.get(id) if role: return {'data': role.to_dict()} else: abort(404, error='Role not exist.')