Exemple #1
0
 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
Exemple #2
0
 def remove_share(self, user_id):
     share = Data_Access.get(user_id=user_id, data_id=self.id)
     if share:
         for s in share:
             Notification.delete(user_id=user_id,
                                 data="/data/{}/{}".format(
                                     self.user.username, self.name))
             s.delete_from_db()
Exemple #3
0
 def delete_from_db(self):
     d = Data_Access.get(data_id=self.id)
     if d:
         for item in d:
             Notification.delete(user_id=item.user_id,
                                 data="/data/{}/{}".format(
                                     self.user.username, self.name))
             item.delete_from_db()
     db.session.delete(self)
     db.session.commit()
Exemple #4
0
 def delete(self, initiator, replier, step):
     valid = self.validate_request(initiator, replier, step, 'delete')
     if not valid[0] == True:
         return  valid
     init = valid[1]
     rep = valid[2]
     del_smp = SMPModel.get_by_users(init, rep)
     if del_smp:
         del_smp.delete_from_db()
     Notification.delete(user=rep, data="/smp/{}_{}/question".format(initiator, replier))
     return {'message': "Succesfully deleted remaining SMP data for {} and {}".format(initiator, replier)}
Exemple #5
0
 def delete(self, username):
     if not username == User.get_username_by_id(session["user_id"]):
         return {
             'message': "You may not access another user's notifications."
         }, 400
     data = self.parser.parse_args()
     if not data['data']:
         NotifModel.delete(user_id=session["user_id"])
     else:
         NotifModel.delete(user_id=session["user_id"], data=data['data'])
     return {
         'message': "Deleted notifications for user {}".format(username)
     }
Exemple #6
0
 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()
Exemple #7
0
 def get(self, username):
     if not username == User.get_username_by_id(session["user_id"]):
         return {
             'message': "You may not access another user's notifications."
         }, 400
     notif = NotifModel.get_all_by_user(session["user_id"])
     if not notif or len(notif) < 1:
         return {'message': "No notifications for this user."}, 404
     result = {'username': username}
     i = 0
     for n in notif:
         result.update(n.json(i))
         i += 1
     return result