def update_status(self, requester, status, reason): now = datetime.utcnow() current_status = self.status self.status = status request_status_change = RequestStatusChange(request=self, user_id=requester.id, from_status=current_status, to_status=status, change_at=now).add( self.session) self.session.flush() Comment(obj_type=OBJ_TYPES_IDX.index("RequestStatusChange"), obj_pk=request_status_change.id, user_id=requester.id, comment=reason, created_on=now).add(self.session) if status == "actioned": edge = self.session.query(GroupEdge).filter_by( id=self.edge_id).one() edge.apply_changes(self) Counter.incr(self.session, "updates")
def cancel_user_request(self, user_request, reason, authorization): # type: (UserGroupRequest, str, Authorization) -> None now = datetime.utcnow() request = Request.get(self.session, id=user_request.id) if not request: raise UserGroupRequestNotFoundException(request) actor = User.get(self.session, name=authorization.actor) if not actor: raise UserNotFoundException(authorization.actor) request_status_change = RequestStatusChange( request=request, user_id=actor.id, from_status=request.status, to_status="cancelled", change_at=now, ).add(self.session) request.status = "cancelled" self.session.flush() Comment( obj_type=OBJ_TYPES["RequestStatusChange"], obj_pk=request_status_change.id, user_id=actor.id, comment=reason, created_on=now, ).add(self.session)
def persist_group_member_changes( session, # type: Session group, # type: Group requester, # type: User member, # type: Union[User, Group] status, # type: str reason, # type: str create_edge=False, # type: bool **updates # type: Any ): # type: (...) -> Request requested_at = datetime.utcnow() if "role" in updates: role = updates["role"] _validate_role(member.member_type, role) get_plugin_proxy().will_update_group_membership(session, group, member, **updates) if create_edge: edge = _create_edge(session, group, member, updates.get("role", "member")) else: edge = _get_edge(session, group, member) if not edge: raise MemberNotFound() changes = _serialize_changes(edge, **updates) request = Request( requester_id=requester.id, requesting_id=group.id, on_behalf_obj_type=member.member_type, on_behalf_obj_pk=member.id, requested_at=requested_at, edge_id=edge.id, status=status, changes=changes, ).add(session) session.flush() request_status_change = RequestStatusChange( request=request, user_id=requester.id, to_status=status, change_at=requested_at).add(session) session.flush() Comment( obj_type=OBJ_TYPES["RequestStatusChange"], obj_pk=request_status_change.id, user_id=requester.id, comment=reason, created_on=requested_at, ).add(session) session.flush() if status == "actioned": edge.apply_changes(request.changes) session.flush() Counter.incr(session, "updates") return request