Exemple #1
0
    def put(self):
        """
        Function to change a view record
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        body_categories = {"view_id": 1, "name": 1}
        view_dict = errorutil.check_fields(self.request.body.decode(),
                                           body_categories, self)

        if view_dict == False:
            return None

        view_id = view_dict["view_id"]
        del view_dict["view_id"]

        if viewutil.change_view(view_id, view_dict, self) == False:
            return None

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "views", view_id, view_dict)

        loggerhandler.log_message("change", formatted_message)

        self.write({"message": "Success"})
Exemple #2
0
    def put(self):
        """
        Function to change a label
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 2) == False:
            return None

        userdata = jwthandler.decode_userdata(self.request.headers["Authorization"])

        body_categories = {"label_id": 1, "label_text": 0, "parent": 0}
        label_dict = errorutil.check_fields(self.request.body.decode(), body_categories, self)

        if label_dict == False:
            return None

        label_id = label_dict["label_id"]
        del label_dict["label_id"]

        if labelutil.change_label(label_id, label_dict, self) == False:
            return None

        formatted_message = loggerhandler.form_message_dictionary(userdata, 
                                                                "label", 
                                                                label_id,
                                                                label_dict)

        loggerhandler.log_message("change", formatted_message)


        self.write({"message":"Success"})
Exemple #3
0
    def post(self):
        """
        Function to create a type record
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        body_categories = {"type": 1}
        type_dict = errorutil.check_fields(self.request.body.decode(),
                                           body_categories, self)

        if type_dict == False or typeutil.create_type(type_dict,
                                                      self) == False:
            return None

        type_id = typeutil.get_type_id(type_dict["type"])

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "node_type", type_id, type_dict)

        loggerhandler.log_message("add", formatted_message)

        self.write({"message": "Success", "payload": type_id})
    def put(self):
        """
        Function to change a relationship record
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 2) == False:
            return None

        body_categories = {"relationship_id": 1, "message": 1}
        relationship_dict = errorutil.check_fields(self.request.body.decode(),
                                                   body_categories, self)

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        if relationship_dict == False:
            return None

        relationship_id = relationship_dict["relationship_id"]
        del relationship_dict["relationship_id"]

        if relationshiputil.change_relationship(relationship_id,
                                                relationship_dict,
                                                self) == False:
            return None

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "relationship", relationship_id, relationship_dict)

        loggerhandler.log_message("change", formatted_message)

        self.write({"message": "Success"})
Exemple #5
0
    def put(self):
        """
        Function to change a node record
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        userdata = jwthandler.decode_userdata(self.request.headers["Authorization"])

        body_categories = {"node_id": 1, "type_id": 0, "view_id": 0, "label_id": 0, "icon":0}
        node_dict = errorutil.check_fields(self.request.body.decode(), body_categories, self)

        if node_dict == False:
            return None

        node_id = node_dict["node_id"]
        del node_dict["node_id"]

        if nodeutil.change_node(node_id, node_dict, self) == False:
            return None

        formatted_message = loggerhandler.form_message_dictionary(userdata, 
                                                                "node", 
                                                                node_id,
                                                                node_dict)
        try:
            loggerhandler.log_message("change", formatted_message)
        except:
            pass

        self.write({"message":"Success"})
Exemple #6
0
    def post(self):
        """
        Function to create a link
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        body_categories = {
            "node_id_1": 1,
            "node_id_2": 1,
            "view_id": 1,
            "relationship_id": 0
        }
        link_dict = errorutil.check_fields(self.request.body.decode(),
                                           body_categories, self)

        link_id = linkutil.create_link(link_dict, self)
        if link_dict == False or link_id == False:
            return None

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "links",
            linkutil.get_link_id(link_dict["node_id_1"],
                                 link_dict["node_id_2"]), link_dict)

        loggerhandler.log_message("add", formatted_message)

        self.write({"message": "Success", "payload": link_id})
Exemple #7
0
    def put(self):
        """
        Function to change a metadata record
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        body_categories = {
            "meta_id": 1,
            "node_id": 0,
            "link_id": 0,
            "category": 0,
            "metadata": 0
        }
        metadata_dict = errorutil.check_fields(self.request.body.decode(),
                                               body_categories, self)

        if "node_id" in metadata_dict and "link_id" in metadata_dict:
            self.set_status(400)
            self.write({
                "message":
                "Too many object id fields. Either use node_id or link_id"
            })
            return None

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        metadata_id = metadata_dict["meta_id"]

        if metadata_dict == False or metadatautil.change_metadata(
                metadata_id, metadata_dict, self) == False:
            return None

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "metadata", metadata_id, metadata_dict)

        loggerhandler.log_message("change", formatted_message)

        self.write({"message": "Success"})
Exemple #8
0
    def put(self):
        """
        Function to change a user password
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        user_data = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        body_categories = {"old_password": 1, "new_password": 1}
        password_dict = errorutil.check_fields(self.request.body.decode(),
                                               body_categories, self)
        print(
            userutil.compare_password(user_data["username"],
                                      password_dict["old_password"]))
        if userutil.compare_password(user_data["username"],
                                     password_dict["old_password"]):
            user_id = user_data["uid"]
            if userutil.change_password(user_id,
                                        password_dict["new_password"]):
                self.write({"message": "Success"})
            else:
                self.set_status(500)
                self.write({"message": "Failed to change password"})
                return None
        else:
            self.write({"message": "Failed to change password"})
            return None

        formatted_message = loggerhandler.form_message_dictionary(
            user_data, "user", user_data["uid"], {
                "old_password": "",
                "new_password": ""
            })

        loggerhandler.log_message("add", formatted_message)
        return None
Exemple #9
0
    def post(self):
        """
        Function to create a metadata record
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 1) == False:
            return None

        body_categories = {
            "node_id": 0,
            "link_id": 0,
            "category": 1,
            "data": 1
        }
        metadata_dict = errorutil.check_fields(self.request.body.decode(),
                                               body_categories, self)

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        if metadata_dict == False:
            return None
        meta_id = 0
        if ("node_id" not in metadata_dict and "link_id" not in metadata_dict):
            self.set_status(400, "Empty object create request")
            self.write({"message": "Missing link_id or node_id field"})
            return None
        else:
            meta_id = metadatautil.create_category(metadata_dict, self)
            if meta_id == False:
                return None

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "metadata", meta_id, metadata_dict)

        loggerhandler.log_message("add", formatted_message)

        self.write({"message": "Success", "payload": meta_id})
Exemple #10
0
    def post(self):
        """
        Function to register a new password
        Inputs: Tornado web request
        Output: Success message
        Caveats: Authentication needs to be passed
        """
        if jwthandler.authorize_action(self, 0) == False:
            return None

        userdata = jwthandler.decode_userdata(
            self.request.headers["Authorization"])

        body_categories = {"username": 1, "password": 1, "privilege": 0}
        user_dict = errorutil.check_fields(self.request.body.decode(),
                                           body_categories, self)

        if user_dict == False or userutil.create_user(user_dict,
                                                      self) == False:
            return None

        username = user_dict["username"]

        token = jwthandler.create_token(userutil.get_uid(username), username,
                                        userutil.get_privilege(username) + 1)
        self.add_header("token", token)

        #sanitise password for logs
        del user_dict["password"]

        formatted_message = loggerhandler.form_message_dictionary(
            userdata, "user", userutil.get_uid(username), user_dict)

        loggerhandler.log_message("add", formatted_message)

        self.write({'message': "Success"})