def post(self, **params): """Logic for creating a team""" team = Team(**params).save() user = User.find_by(id_=get_jwt_identity()) team.members.connect(user) # pylint:disable=no-member _notify_of_team_creation(team) return team
def patch(self, **params): """Logic for updating a user""" user = User.find_by(id_=params.pop("id")) if "password" in params: if not user.check_password(params.pop("old_password", None)): return users_validator.raise_old_password_was_wrong() user.update(**params) return user
def delete(self, **params): drive = Drive.find_by(id_=params["drive_id"]) if drive.owner == User.find_by(id_=get_jwt_identity()): try: Drive.find_by(id_=params["drive_id"]).delete() return no_content() except Drive.NotFound: abort(404, "Drive not Found") else: abort(403)
def post(self, **params): """Logic for adding a single team member""" user = User.find_by(id_=get_jwt_identity()) team = Team.find_by(join_key=params["join_key"], force=False) if not team: return abort(404, "this invite link is not valid") if user in team.members: return abort(409, "user already in team") team.members.connect(user) return team
def _get_user_from_google_token(token): """Checks if a user can be obtained with the given token and if not, creates a new user. :param token: id_token returned by google login :return: instance of User """ google_id, email = validate_google_id_token(token) google_auth = GoogleOAuth.find_by(user_id=google_id, force=False) if not google_auth: user = User.find_by(email=email, force=False) if not user: user = User(email=email, username=email, password=None).save() google_auth = GoogleOAuth(user_id=google_id).save() google_auth.user_rel.connect(user) # pylint:disable=no-member else: user = google_auth.user return user
def get(self, **params): # pylint: disable=W0613 """Logic for querying several teams""" user = User.find_by(id_=get_jwt_identity()) teams = list(user.teams) return teams