def approve_join_request(): join_request_hash = current_request.get_json()["hash"] join_request = _get_join_request(join_request_hash) collaboration = join_request.collaboration confirm_collaboration_admin(collaboration.id) user_id = join_request.user.id if collaboration.is_member(user_id): raise Conflict(f"User {join_request.user.name} is already a member of {collaboration.name}") mail_accepted_declined_join_request({ "salutation": f"Dear {join_request.user.name}", "base_url": current_app.app_config.base_url, "administrator": current_user_name(), "join_request": join_request, "user": join_request.user}, join_request, True, [join_request.user.email]) collaboration_membership = CollaborationMembership(user_id=user_id, collaboration_id=collaboration.id, role="member", created_by=current_user_uid(), updated_by=current_user_uid()) join_request.status = STATUS_APPROVED db.session.merge(collaboration_membership) db.session.merge(join_request) res = {'collaboration_id': collaboration.id, 'user_id': user_id} return res, 201
def deny_join_request(): join_request_hash = current_request.get_json()["hash"] rejection_reason = current_request.get_json()["rejection_reason"] join_request = _get_join_request(join_request_hash) confirm_collaboration_admin(join_request.collaboration.id) mail_accepted_declined_join_request({"salutation": f"Dear {join_request.user.name}", "base_url": current_app.app_config.base_url, "rejection_reason": rejection_reason, "administrator": current_user_name(), "join_request": join_request, "user": join_request.user}, join_request, False, [join_request.user.email]) join_request.status = STATUS_DENIED join_request.rejection_reason = rejection_reason db.session.merge(join_request) return None, 201
def deny_request(collaboration_request_id): collaboration_request = CollaborationRequest.query.get(collaboration_request_id) confirm_organisation_admin_or_manager(collaboration_request.organisation_id) rejection_reason = current_request.get_json()["rejection_reason"] user = collaboration_request.requester mail_accepted_declined_collaboration_request({"salutation": f"Dear {user.name}", "base_url": current_app.app_config.base_url, "administrator": current_user_name(), "rejection_reason": rejection_reason, "collaboration": {"name": collaboration_request.name}, "organisation": collaboration_request.organisation, "user": user}, collaboration_request.name, collaboration_request.organisation, False, [user.email]) collaboration_request.status = STATUS_DENIED collaboration_request.rejection_reason = rejection_reason db.session.merge(collaboration_request) return None, 201
def approve_request(collaboration_request_id): collaboration_request = CollaborationRequest.query.get(collaboration_request_id) confirm_organisation_admin_or_manager(collaboration_request.organisation_id) client_data = current_request.get_json() attributes = ["name", "short_name", "description", "organisation_id", "accepted_user_policy", "logo", "website_url", "logo"] # take the data from client_data as it can be different data = {"identifier": str(uuid.uuid4())} for attr in attributes: data[attr] = client_data.get(attr, None) assign_global_urn_to_collaboration(collaboration_request.organisation, data) data["status"] = STATUS_ACTIVE res = save(Collaboration, custom_json=data) collaboration = res[0] user = collaboration_request.requester admin_collaboration_membership = CollaborationMembership(role="admin", user_id=user.id, collaboration_id=collaboration.id, created_by=user.uid, updated_by=user.uid) db.session.merge(admin_collaboration_membership) mail_accepted_declined_collaboration_request({"salutation": f"Dear {user.name}", "base_url": current_app.app_config.base_url, "administrator": current_user_name(), "collaboration": collaboration, "organisation": collaboration_request.organisation, "user": user}, collaboration.name, collaboration_request.organisation, True, [user.email]) collaboration_request.status = STATUS_APPROVED db.session.merge(collaboration_request) return res
def test_current_user_name(self): with self.app.app_context(): session["user"] = {"uid": "urn:john", "admin": True, "name": "some_name"} self.assertEqual("some_name", current_user_name())