async def assign_permissions(instance, message_object, uID, *permissions): if get_permissions(instance.cwd + '/resources/permissions', message_object.author.id)['main'] < 3: await instance.send_message( message_object.channel, '<@{id}> You are not authorized to give permissions'.format( id=message_object.author.id)) return pArgs = [] for permission in permissions: tempArgs = split_nospace(permission, '=') if len(tempArgs) != 2: return try: tempArgs[1] = int(tempArgs[1]) except ValueError: return pArgs.append((tempArgs[0], tempArgs[1])) with open(instance.cwd + '/resources/permissions') as f: temp = json.load(f) for key, value in pArgs: temp[uID][key] = value with open(instance.cwd + '/resources/permissions', 'w') as f: json.dump(temp, f) await instance.send_message( message_object.channel, "The user <@{id}> was give the permissions '{permissions}'".format( id=uID, permissions=', '.join(permissions)))
def test_mkdir(self): shutil.rmtree(self.dirname) self.assertFalse(os.path.isdir(self.dirname)) (ret, out, err) = utils.run_command('gfal-mkdir', 'file://' + self.dirname) self.assertTrue(os.path.isdir(self.dirname)) self.assertEqual(utils.get_permissions(self.dirname), '755') self.assertEqual(len(out), 0) self.assertEqual(ret, 0)
def test_mkdir_recursive(self): d = self.dirname + '/subdir/subdir' shutil.rmtree(self.dirname) self.assertFalse(os.path.isdir(d)) (ret, out, err) = utils.run_command('gfal-mkdir', '-p file://' + d) self.assertTrue(os.path.isdir(d)) self.assertEqual(utils.get_permissions(d), '755') self.assertEqual(len(out), 0) self.assertEqual(ret, 0)
async def on_message(instance, command, args, message_object): if not command == 'reload': return False perm = get_permissions(instance.cwd + '/resources/permissions', message_object.author.id) if perm.get('main', 0) > 1 or perm.get('plugins', 0) > 0: await instance.send_message(message_object.channel, 'Reloading plugins') await instance.plugin_manager.reload_plugins() else: await instance.send_message( message_object.channel, '<@{id}> You are not authorized to reload the plugins'.format( id=message_object.author.id)) return True
async def list_permissions(instance, message_object, uID, *permissions): rawPerms = get_permissions(instance.cwd + '/resources/permissions', uID) if len(permissions) > 0: temp = rawPerms.copy() for perm in temp: if perm not in permissions: rawPerms.pop(perm) if len(rawPerms) == 0: await instance.send_message( message_object.channel, "The user <@{id}> has non of the requested permissions".format( id=uID)) return permissions = list( map(lambda x: '{}={}'.format(x[0], x[1]), rawPerms.items())) await instance.send_message( message_object.channel, "The user <@{id}> has the permissions:\n*{permissions}".format( id=uID, permissions='\n*'.join(permissions)))