def build_relations(self, props, override_tags): """Create all relations on the artifact object as described in props.""" self._set_full_tags(props, override_tags) if props.get("team_id") is not None: self._connect_relation(self.neo.team, Team.find(props["team_id"])) if props.get("user_id") is not None: self._connect_relation(self.neo.user, User.find(props["user_id"]))
def post(self, **params): current_user = User.find(get_jwt_identity()) if (not current_user.google) or (not current_user.google.has_offline_access): abort(403, "No google account connected") team_id = params.pop("team_id") drive = Drive(**params).save() try: team = Team.find(team_id) team.drive_rel.connect(drive) team.save() except AttemptedCardinalityViolation: drive.delete() abort(409, "Team already has drive connected") drive.owner_rel.connect(User.find(get_jwt_identity())) drive.save() return drive
def patch(self, **params): user = User.find(params["id"]) google_auth = user.google if not google_auth: abort(404, "google oauth not found") google_auth.set_credentials(params["auth_code"]) google_auth.save() return user
def put(self, **params): user = User.find(params["id"]) try: google_oauth = GoogleOAuth.create_from_id_token(params["id_token"]) google_oauth.user_rel.connect(user) return user except GoogleOAuthConflict as err: abort(409, err.message)
def delete(self, **params): user = User.find(params["id"]) google_auth = user.google if not google_auth: abort(404, "google oauth not found") try: google_auth.revoke_access() except EmptyCredentialsError: abort(404, "google oauth has no offline access") except RequestError: abort(502, "could not revoke access") return user
def delete(self, **params): """Logic for deleting a user""" user = User.find(params["id"]) user.delete() return no_content()
def get(self, **params): """get a single user""" return User.find(params["id"])