def test_find_by_id(self): with self.app_context: member_1, _ = self.add_member_to_db(self.member_1, self.role_1) member = MemberModel.find_by_id(member_1.id) self.assertEqual(member.email, self.EMAIL)
def post(self): member_id = request.form.get('member_id') if MemberModel.find_by_id(member_id): message = "Correct member id" else: message = "Wrong member id" return render_template('form.html', message=message)
def test_get_permissions(self): with self.app_context: member_1, role = self.add_member_to_db(self.member_1, self.role_1) permission = self.add_permission_to_db(self.permission_1) role.permissions.append(permission) member = MemberModel.find_by_id(member_1.id) self.assertEqual(member.get_permissions(), [permission.permission_name])
def test_meetings_members_relation(self): with self.app_context: meeting, member, _ = self.add_meeting_to_db( self.meeting_1, self.member_1, self.role_1) meeting = MeetingModel.find_by_id(meeting.id) member = MemberModel.find_by_id(member.id) meeting.members.append(member) self.assertEqual(meeting.members[0].email, member.email)
def get_member(member_id: int) -> ApiResponse: member = MemberModel.find_by_id(member_id) if not member: abort(404, description=ERROR_404.format("Member", "id", member_id)) return ( jsonify({ "member": member_schema.dump(member), }), 200, )
def test_projects_members_relation(self): with self.app_context: self.role_1.save_to_db() self.member_1.save_to_db() project_id = self.project_1.save_to_db().id member_id = self.member_1.save_to_db().id project = ProjectModel.find_by_id(project_id) member = MemberModel.find_by_id(member_id) project.members.append(member) self.assertEqual(project.members[0].email, "*****@*****.**")
def deactivate_member(member_id: int) -> ApiResponse: member = MemberModel.find_by_id(member_id) if not member: abort(404, description=ERROR_404.format("Member", "id", member_id)) member.is_active = False member.save_to_db() return ( jsonify({ "message": DEACTIVATED.format("Member"), "member": member_schema.dump(member), }), 200, )
def put_member(member_id: int) -> ApiResponse: member = MemberModel.find_by_id(member_id) identity = get_jwt_identity() if member and identity["id"] != member.id: abort( 401, description=ERROR_401, ) if not member: abort( 404, description=ERROR_404.format("Member", "id", member_id), ) member_json = request.get_json() member_by_email = MemberModel.find_by_email(member_json.get("email")) if member_by_email and member_by_email.id != member_id: abort( 409, description=ERROR_409.format( "Member", "email", member_json.get("email"), ), ) member.email = member_json.get("email") member.mobile_phone = member_json.get("mobile_phone") member.first_name = member_json.get("first_name") member.last_name = member_json.get("last_name") member.linkedin_profile = member_json.get("linkedin_profile") member.github_profile = member_json.get("github_profile") member.twitter_profile = member_json.get("twitter_profile") member.profile_picture = member_json.get("profile_picture") member.save_to_db() return ( jsonify({ "message": MODIFIED.format("Member"), "member": member_schema.dump(member), }), 200, )
def change_member_password(member_id: int) -> ApiResponse: member = MemberModel.find_by_id(member_id) identity = get_jwt_identity() if member and identity["id"] != member.id: abort( 401, description=ERROR_401, ) if not member: abort(404, description=ERROR_404.format("Member", "id", member_id)) member_json = request.get_json() member.password_hash = generate_password_hash(member_json.get("password")) member.save_to_db() return ( jsonify({ "message": PASSWORD_MODIFIED, "member": member_schema.dump(member), }), 200, )
def add_claims_to_jwt(identity: Dict) -> MemberJSON: return { "permissions": MemberModel.find_by_id(identity["id"]).get_permissions() }