def post(self): user = get_jwt_identity() # claims = get_jwt_claims() # if not claims['manager']: # return {'msg': 'Manager rights needed'}, 403 data = ProjectRes.parser.parse_args() print(data['project_members']) if Project.find_by_project_name(data['project_name']): return {'msg': 'Project already exists'}, 400 proj = Project(id=None, **data, owner=user) proj.members.append(User.find_by_id(user)) err = [] resp = {'msg': 'Project created successfully', 'err': err} if data['project_members']: for member in data['project_members']: mem = User.find_by_username(member['username']) if mem: proj.members.append(mem) else: err.append(member['username']) proj.create_project() return resp, 201
def editMembers(self, members: List): original_users = self.members updated_users = [] if not members: return for mem in members: uname = mem['username'] mem = User.find_by_username(uname) if mem: updated_users.append(mem) if self.owner not in updated_users: updated_users.append(self.owner) # Above line is to prevent owner to to lose ownership deleted_members = set(original_users) - set(updated_users) new_members = set(updated_users) - set(original_users) for member in deleted_members: self.members.remove(member) for member in new_members: self.members.append(member)
def authenticate(username, password): user = User.find_by_username(username) if user and safe_str_cmp(user.password, password): return user
def authenticate(username, password): user = User.find_by_username(username) if user and safe_str_cmp( user.password.encode('utf-8'), password.encode('utf-8') ): return user