def post(self, current_user, research): relationship = ResearchRelationship.get(research.key, current_user.email) if not relationship or relationship.type != RelationshipType.INVITED: return bad_request('You not invited.') relationship.type = RelationshipType.REJECTED relationship.put() return ok_msg('Invitation rejected.')
def post(self, research, user, current_user): relationship = ResearchRelationship.get(research.key, user.email) if not relationship or relationship.type != RelationshipType.WANTS_TO_JOIN: return bad_request('User don\'t want to join.') relationship.type = RelationshipType.REJECTED relationship.put() return ok_msg('Researcher rejected.')
def wrapper(*args, **kwargs): if 'research_id' not in kwargs: return bad_request('To use insert_research wrapper research_id must be in url.') _id = kwargs['research_id'] research = Research.get(int(_id)) if research is None: return research_not_found(_id) del kwargs['research_id'] kwargs['research'] = research return func(*args, **kwargs)
def wrapper(*args, **kwargs): if 'user_id' not in kwargs: return bad_request('To use insert_user wrapper user_id must be in url.') _id = kwargs['user_id'] user = User.get(int(_id)) if user is None: return user_not_found(_id) del kwargs['user_id'] kwargs['user'] = user return func(*args, **kwargs)
def wrapper(*args, **kwargs): if 'message_id' not in kwargs: return bad_request('To use insert_message wrapper message_id must be in url.') _id = kwargs['message_id'] message = Message.get(int(_id)) if message is None: return message_not_found(_id) del kwargs['message_id'] kwargs['message'] = message return func(*args, **kwargs)
def wrapper(*args, **kwargs): if 'forum_id' not in kwargs: return bad_request('To use insert_forum wrapper forum_id must be in url.') _id = kwargs['forum_id'] forum = Forum.get(int(_id)) if forum is None: return forum_not_found(_id) del kwargs['forum_id'] kwargs['forum'] = forum return func(*args, **kwargs)
def put(self, current_user): json_request = request.json new_password = json_request['newPassword'] old_password = json_request['oldPassword'] hashed_old_password = hash_password(old_password) if current_user.hashed_password == hashed_old_password: hashed_new_password = hash_password(new_password) current_user.hashed_password = hashed_new_password current_user.put() return ok_msg('Password updated.') else: return bad_request('Incorrect old password.')
def wrapper(*args, **kwargs): current_user = kwargs['current_user'] if 'research' in kwargs: research = kwargs['research'] elif 'forum': forum = kwargs['forum'] research = forum.research_key.get() else: return bad_request("Can't get info about research.") if __is_researcher(research, current_user) or current_user.is_admin: return func(*args, **kwargs) else: return forbidden('You must be researcher to call this API.')
def post(self, research, user, current_user): relationship = ResearchRelationship.get(research.key, user.email) if not relationship or relationship.type != RelationshipType.WANTS_TO_JOIN: return bad_request('User don\'t want to join.') research.researchers_keys.append(user.key) research.put() relationship.type = RelationshipType.APPROVED relationship.put() user.researcher_in += 1 user.put() return ok_msg('Researcher accepted.')
def post(self, current_user, research): relationship = ResearchRelationship.get(research.key, current_user.email) if not relationship or relationship.type != RelationshipType.INVITED: return bad_request('You not invited.') research.researchers_keys.append(current_user.key) research.put() relationship.type = RelationshipType.ACCEPTED relationship.put() current_user.researcher_in += 1 current_user.put() return ok_msg('Invitation accepted.')
def post(self, current_user, research): researcher_email = request.json['new_researcher'] researcher = User.by_email(researcher_email) if not researcher: return not_found('User with email not found.') if researcher.key in research.researchers_keys \ or research.supervisor_key == researcher.key: return bad_request('User already is researcher.') research.researchers_keys.append(researcher.key) research.put() self.__add_relationship(research.key, researcher_email) return ok_msg('Researcher is added.')
def post(self, research, current_user): recipient = request.json['email'] name = request.json['name'] text = request.json.get('text', '') if self.__relationship_exists(research, recipient): return bad_request('Already invited.') self.__add_relationship(research, recipient) supervisor = current_user.name title = research.title description = research.brief_desc subj_view = InviteToJoinSubj(supervisor, title) body_view = InviteToJoin(supervisor, title, description, name, text) sender.send_email(subj_view, body_view, recipient) return ok_msg("Invitation send to {0}".format(recipient))
def post(self, research, current_user): if self.__relationship_exists(research, current_user.email): return bad_request('Already requested.') self.__add_relationship(research, current_user.email) supervisor = research.supervisor_key.get() user_name = current_user.name recipient = supervisor.email supervisor_name = supervisor.name title = research.title text = request.json.get('text', '') subj_view = ReqToJoinSubj(user_name, title) body_view = ReqToJoin(user_name, title, supervisor_name, text) sender.send_email(subj_view, body_view, recipient) return ok_msg('Request was send to research supervisor.')
def post(self): json_request = request.json email = json_request['email'] name = json_request['name'] password = json_request['password'] cv = json_request.get('cv', '') user = User.by_email(email) if user: return bad_request('User with email {0} already exists'.format(email)) user = User(name=name, email=email, cv=cv, is_admin=False, status=StatusType.ACTIVE, hashed_password=hash_password(password)) user_key = user.put() return created(Token(user_key.id()).json())