def post(self, *args, **kwargs): project_id = self.get_argument('projectId', None) owner = self.get_argument('owner', None) project_name = self.get_argument('project_name', None) project_permalink = self.get_argument('project_pemalink', None) roles = self.get_arguments('roles', None) extended_date = self.get_argument('extended_date', None) project = None if project_id: project = self.get_valid_project(project_id) elif owner and project_name: permalink = owner + '/' + project_name project = self.get_valid_project(project_id, permalink) elif project_permalink: project = self.get_valid_project(project_id=None, permalink=project_permalink) else: self.send_error(400) if roles: new_roles = [role for role in roles if role not in project.roles] Role.create_role_map(new_roles, project, self.current_user, map=0) project.roles.extend(roles) project.update(set__roles=set(list(project.roles))) if extended_date and project.is_todo: extended_date = millisecondToDatetime(extended_date) project.update(set__end_date=extended_date) self.write(project.to_json())
def post(self, *args, **kwargs): project_id = self.get_argument('projectId', None) owner = self.get_argument('owner', None) project_name = self.get_argument('project_name', None) project_permalink = self.get_argument('project_pemalink', None) roles = self.get_arguments('roles', None) project = None if project_id: project = self.get_valid_project(project_id) elif owner and project_name: permalink = owner + '/' + project_name project = self.get_valid_project(project_id, permalink) elif project_permalink: project = self.get_valid_project(project_id=None, permalink=project_permalink) else: self.send_error(400) response = {} if roles: new_roles = [role for role in roles if role not in project.roles] Role.create_role_map(new_roles, project, self.current_user, map=0) project.roles.extend(roles) project.update(set__roles=set(list(project.roles))) self.write(project.to_json())
def post(self, *args, **kwargs): ''' { projectId : 1, permissions: {'can_edit_story': 1, 'can_delete_story'; 0 ..}, role: admin project_permalink: somesh/clearsoup } ''' project_id = self.get_argument('projectId', None) owner = self.get_argument('owner', None) project_name = self.get_argument('project_name', None) project_permalink = self.get_argument('project_pemalink', None) role = self.get_argument('role') project = None response = {} if project_id: project = self.get_valid_project(project_id) elif owner and project_name: permalink = owner + '/' + project_name project = self.get_valid_project(project_id, permalink) elif project_permalink: project = self.get_valid_project(project_id=None, permalink=project_permalink) else: self.send_error(400) if self.current_user not in project.members: raise HTTPError(404, **{'reason': 'Project not found'}) if role == 'admin': self.send_error(400) else: try: role = Role.objects.get(role=role, project=project) self.data['permissions'] = ast.literal_eval(self.data['permissions']) for key, value in self.data['permissions'].iteritems(): position = PROJECT_PERMISSIONS.index(key) test_bit = Role.testBit(role.map, position) if value == 1: if not test_bit: new_map = Role.toggleBit(role.map, position) role.update(set__map=new_map) elif value == 0: if test_bit: new_map = Role.toggleBit(role.map, position) role.update(set__map=new_map) permission_dict = self.generate_readable_permission_json(role) response = {'permission_dict' : permission_dict, 'permission_object': role.to_json()} self.write(response) except Role.DoesNotExist, error: raise HTTPError(404, **{'reason': self.error_message(error)})
def create_role(self, project, creating_project): if creating_project: for role in project.roles: r = Role(project=project, role=role, map=permission_map[role], created_by=self.current_user, updated_by=self.current_user) r.save() else: pass
def generate_readable_permission_json(self, group=None): permission_dict = {} for perm in PROJECT_PERMISSIONS: if Role.testBit(group.map, PROJECT_PERMISSIONS.index(perm)): permission_dict[perm] = 1 else: permission_dict[perm] = 0 return permission_dict
def generate_readable_permission_json(self, role=None): permission_dict = {} for perm in PROJECT_PERMISSIONS: if Role.testBit(role.map, PROJECT_PERMISSIONS.index(perm)): permission_dict[perm] = 1 else: permission_dict[perm] = 0 return permission_dict
def check_permission(self, project, value): team = None try: team = Team.objects.get(project=project, user=self.current_user) permission_flag = False if Role.testBit(team.role.map, PROJECT_PERMISSIONS.index(value)): permission_flag = True return permission_flag except Team.DoesNotExist: msg = 'Not authorized to perform this action' raise HTTPError(500, **{'reason': msg})
def check_permission(self, project, value): team = None try: team = Team.objects.get(project=project, user=self.current_user) permission_flag = False if Role.testBit(team.role.map, PROJECT_PERMISSIONS.index(value)): permission_flag = True return permission_flag except Team.DoesNotExist: msg = 'Not permitted to perform this action' raise HTTPError(500, **{'reason':msg})
def check_permission(self, permission): permission_flag = False if Role.testBit(permission.map, PROJECT_PERMISSIONS.index('can_delete_task')): permission_flag = True return permission_flag