def post(self, initiator, replier, step): valid = self.validate_request(initiator, replier, step, 'post') if not valid[0] == True: return valid init = valid[1] rep = valid[2] smp_object = SMPModel.get_by_users(init, rep) data = self.parser.parse_args() if not smp_object: if step == 'question' and data['question']: Notification.add("/smp/{}_{}/question".format(initiator, replier), rep.id) return SMPModel(init.id, rep.id, data['question']).save_to_db().json() return {'message': "You have to start the SMP by posting a question to /smp/{}_{}/question".format(initiator, replier)}, 400 if not data['data']: return {'message': "You have to post data to the resource!"}, 400 data = data['data'] if step == 'question': return {'message': "The SMP has already been initiated. Continue with the next steps."}, 400 for i in range(5): if step == self.steps[i]: answer = smp_object.update(i, data) if not answer: return {'message': "The requested step resource does not exist in SMP or is not allowed to be modified at this phase of the protocol."}, 404 return answer return {'message': "Illegal request."}, 404
def update(self, name=None, user_id=None, key=None, data=None, shares=None): if name: self.name = name if user_id: self.user_id = user_id if key: self.key = key if data: self.data = data if shares: if not Data_Access.get(user_id=shares, data_id=self.id): Notification.add( "/data/{}/{}".format(self.user.username, self.name), shares) Data_Access(shares, self.id).save_to_db() db.session.commit()