예제 #1
0
파일: action.py 프로젝트: skarphed/skarphed
 def decrease_order(self):
     """
     Decreases the order of this MenuItem
     """
     db = Database()
     if self.get_menu_id() is not None:
         stmnt = "SELECT MAX(MNI_ORDER) AS NEWORDER FROM MENUITEMS WHERE MNI_MNU_ID = ? AND MNI_ORDER < ? ;"
         cur = db.query(stmnt, (self.get_menu_id(), self.get_order()))
         row = cur.fetchonemap()
         if row is not None:
             if row["NEWORDER"] is None:
                 return
             temp_order = self.get_order()
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ORDER = ? AND MNI_MNU_ID = ? ;"
             db.query(stmnt, (temp_order, row["NEWORDER"], self.get_menu_id()),commit=True)
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ID = ? ;"
             db.query(stmnt, (row["NEWORDER"], self.get_id()),commit=True)
             db.commit()
             PokeManager.add_activity(ActivityType.MENU)
     elif self.get_parent_menu_item_id() is not None:
         stmnt = "SELECT MAX(MNI_ORDER) AS NEWORDER FROM MENUITEMS WHERE MNI_MNI_ID = ? AND MNI_ORDER < ? ;"
         cur = db.query(stmnt, (self.get_parent_menu_item_id(), self.get_order()))
         row = cur.fetchonemap()
         if row is not None:
             if row["NEWORDER"] is None:
                 return
             temp_order = self.get_order()
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ORDER = ? AND MNI_MNI_ID = ? ;"
             db.query(stmnt, (temp_order, row["NEWORDER"], self.get_parent_menu_item_id()),commit=True)
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ID = ? ;"
             db.query(stmnt, (row["NEWORDER"], self.get_id()),commit=True)
             db.commit()
             PokeManager.add_activity(ActivityType.MENU)
예제 #2
0
    def assign_to(self,user):
        """
        Assigns this role to a user
        """
        session_user = Session.get_current_session_user()

        db = Database()
        
        #check if sessionuser has role
        
        has_role = session_user.has_role(self)

        stmnt = "SELECT COUNT(URI_RIG_ID) AS CNT FROM USERRIGHTS WHERE URI_RIG_ID IN \
            (SELECT RRI_RIG_ID FROM ROLERIGHTS WHERE RRI_ROL_ID = ? ) ;"
        cur = db.query(stmnt,(self._id,))
        res = cur.fetchone()[0]

        has_all_permissions_of_role = res == len(self.get_permissions())

        if not has_role and not has_all_permissions_of_role:
            raise PermissionException(PermissionException.get_msg(7))

        for role in user.get_grantable_roles():
            if role["name"] == self._name:
                stmnt = "UPDATE OR INSERT INTO USERROLES (URO_USR_ID, URO_ROL_ID) \
                    VALUES (?,?) MATCHING (URO_USR_ID, URO_ROL_ID) ;";
                db.query(stmnt, (user.get_id(),self._id),commit=True)
                PokeManager.add_activity(ActivityType.USER)
                return
        raise PermissionException(PermissionException.get_msg(8))
예제 #3
0
파일: action.py 프로젝트: skarphed/skarphed
 def move_to_bottom_order(self):
     """
     Moves this menuitem to the bottom-order
     """
     db = Database()
     if self.get_menu_id() is not None:
         stmnt = "SELECT MIN(MNI_ORDER) AS NEWORDER FROM MENUITEMS WHERE MNI_MNU_ID = ? ;"
         cur = db.query(stmnt, (self.get_menu_id(),))
         row = cur.fetchonemap()
         if row is not None:
             if row["NEWORDER"] is None:
                 return
             temp_order = self.get_order()
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ORDER = ? AND MNI_MNU_ID = ? ;"
             db.query(stmnt, (temp_order, row["NEWORDER"], self.get_menu_id()),commit=True)
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ID = ? ;"
             db.query(stmnt, (row["NEWORDER"], self.get_id()),commit=True)
             db.commit()
             PokeManager.add_activity(ActivityType.MENU)
     elif self.get_parent_menu_item_id() is not None:
         stmnt = "SELECT MIN(MNI_ORDER) AS NEWORDER, MNI_ID FROM MENUITEMS WHERE MNI_MNI_ID = ? ;"
         cur = db.query(stmnt, (self.get_parent_menu_item_id(),))
         row = cur.fetchonemap()
         if row is not None:
             if row["NEWORDER"] is None:
                 return
             temp_order = self.get_order()
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ORDER = ? AND MNI_MNI_ID = ? ;"
             db.query(stmnt, (temp_order, row["NEWORDER"], self.get_parent_menu_item_id()),commit=True)
             stmnt = "UPDATE MENUITEMS SET MNI_ORDER = ? WHERE MNI_ID = ? ;"
             db.query(stmnt, (row["NEWORDER"], self.get_id()),commit=True)
             db.commit()
             PokeManager.add_activity(ActivityType.MENU)
예제 #4
0
파일: action.py 프로젝트: skarphed/skarphed
 def delete(self):
     """
     Deletes this MenuItem from DB
     """        
     db = Database()
     stmnt = "DELETE FROM MENUITEMS WHERE MNI_ID = ? ;"
     db.query(stmnt, (self.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #5
0
파일: action.py 프로젝트: skarphed/skarphed
 def delete(self):
     """
     Deletes the ActionList from the DB
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONLISTS WHERE ATL_ID = ? ;"
     db.query(stmnt, (self.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #6
0
파일: action.py 프로젝트: skarphed/skarphed
 def delete(self):
     """
     Deletes this Action from the database
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONS WHERE ACT_ID = ? ;"
     db.query(stmnt, (self.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #7
0
 def remove_permission(cls, permission, module=""):
     """
     removes a permission from the database
     """
     db = Database()
     stmnt = "DELETE FROM RIGHTS WHERE RIG_NAME = ? ;"
     db.query(stmnt, (permission,),commit=True)
     PokeManager.add_activity(ActivityType.PERMISSION)
예제 #8
0
 def delete(self):
     """
     deletes this role from the database
     """
     db = Database()
     stmnt = "DELETE FROM ROLES WHERE ROL_ID = ? ;"
     db.query(stmnt,(self._id,),commit=True)
     PokeManager.add_activity(ActivityType.ROLE)
예제 #9
0
파일: action.py 프로젝트: skarphed/skarphed
 def delete_actions_with_widget(cls, widget):
     """
     Deletes all actions that contain this widget
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONS WHERE ACT_WGT_ID = ? ;"
     db.query(stmnt,(widget.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return
예제 #10
0
파일: action.py 프로젝트: skarphed/skarphed
 def delete(self):
     """
     Deletes this menu from the database
     """
     db = Database()
     stmnt = "DELETE FROM MENUS WHERE MNU_ID = ? ;"
     db.query(stmnt, (self.get_id(),),commit=True)
     db.commit()
     PokeManager.add_activity(ActivityType.MENU)
예제 #11
0
파일: action.py 프로젝트: skarphed/skarphed
 def delete_actions_with_module(cls, module):
     """
     Deletes all actions that contain this widget
     """
     db = Database()
     stmnt = "DELETE FROM ACTIONS WHERE ACT_WGT_ID IN (SELECT WGT_ID FROM WIDGETS WHERE WGT_MOD_ID = ?) ;"
     db.query(stmnt,(module.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return
예제 #12
0
파일: action.py 프로젝트: skarphed/skarphed
 def remove_menu_item(self, menu_item):
     """
     Removes a MenuItem (SubmenuItem) assigned to this MenuItem
     """
     menu_item_id = menu_item.get_id()
     menu_item.set_parent_menu_item_id(None)
     db = Database()
     stmnt = "UPDATE MENUITEMS SET MNI_MNI_ID = NULL WHERE MNI_ID = ? ;"
     db.query(stmnt, (self.get_id(), menu_item_id),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #13
0
 def create_permission(cls, permission, module=""):
     """
     Creates a new permission in database
     """
     db = Database()
     new_id = db.get_seq_next('RIG_GEN')
     stmnt = "INSERT INTO RIGHTS (RIG_ID, RIG_NAME) VALUES (?,?) ;"
     db.query(stmnt,(new_id,module+"."+permission),commit=True)
     PokeManager.add_activity(ActivityType.PERMISSION)
     return module+"."+permission
예제 #14
0
    def revoke_from(self, user):
        """
        Revokes a role from a user 
        """
        session_user = Session.get_current_session_user()

        db = Database()
        stmnt = "DELETE FROM USERROLES WHERE URO_USR_ID = ? AND URO_ROL_ID = ? ;";
        db.query(stmnt,(user.get_id(),self._id),commit=True)
        PokeManager.add_activity(ActivityType.USER)
예제 #15
0
파일: action.py 프로젝트: skarphed/skarphed
 def add_menu_item(self, menu_item):
     """
     Adds a MenuItem as SubMenu-Component to this MenuItem
     """
     menu_item_id = menu_item.get_id()
     menu_item.set_parent_menu_item_id(self.get_id())
     db = Database()
     stmnt = "UPDATE MENUITEMS SET MNI_MNI_ID = ? WHERE MNI_ID = ? ;"
     db.query(stmnt, (self.get_id(), menu_item_id),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #16
0
파일: action.py 프로젝트: skarphed/skarphed
 def assign_action_list(self, action_list):
     """
     Assigns an ActionList to this MenuItem
     """
     action_list_id = action_list.get_id()
     self.set_action_list_id(action_list_id)
     db = Database()
     stmnt = "UPDATE MENUITEMS SET MNI_ATL_ID = ? WHERE MNI_ID = ? ;"
     db.query(stmnt, (action_list_id, self.get_id()),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #17
0
파일: action.py 프로젝트: skarphed/skarphed
 def set_name(self,name, ignore_db=False):
     """
     Sets the name of this MenuItem
     """
     self._name = unicode(name)
     if self.get_id() is not None and not ignore_db:
         db = Database()
         stmnt = "UPDATE MENUITEMS SET MNI_NAME = ? WHERE MNI_ID = ? ;"
         db.query(stmnt, (self._name, self.get_id()),commit=True)
         PokeManager.add_activity(ActivityType.MENU)
예제 #18
0
파일: action.py 프로젝트: skarphed/skarphed
 def add_menu_item(self, menu_item):
     """
     Adds a MenuItem to this Menu
     MenuItem only gets added if its not already assigned here
     """
     if menu_item not in self._children:
         self._chilren.append(menu_item)
         db = Database()
         stmnt = "UPDATE MENUITEMS SET MNI_MNU_ID = ? WHERE MNI_ID = ? ;"
         db.query(stmnt, (self.get_id(),menu_item.get_id()),commit=True)
         PokeManager.add_activity(ActivityType.MENU)
예제 #19
0
파일: action.py 프로젝트: skarphed/skarphed
 def set_menu_id(self, parent_menu_id, ignore_db=False):
     """
     Sets the menu_id of this menu
     """
     self._menu_id = parent_menu_id
     self._parent_menu_item = None
     self._parent_menu_item_id = None
     if self.get_id() is not None and not ignore_db:
         db = Database()
         stmnt = "UPDATE MENUITEMS SET MNI_MNU_ID = ?, MNI_MNI_ID = NULL WHERE MNI_ID = ? ;"
         db.query(stmnt, (self._menu_id, self.get_id()),commit=True)
         PokeManager.add_activity(ActivityType.MENU)
예제 #20
0
파일: action.py 프로젝트: skarphed/skarphed
 def create_action_list(cls, action_list_name = "new actionlist"):
     """
     This function creates a new ActionList
     """
     action_list = ActionList()
     action_list.set_name(action_list_name)
     db = Database()
     action_list.set_id(db.get_seq_next('ATL_GEN'))
     stmnt = "INSERT INTO ACTIONLISTS VALUES (?,?);"
     db.query(stmnt, (action_list.get_id(), action_list.get_name()),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return action_list
예제 #21
0
파일: action.py 프로젝트: skarphed/skarphed
 def create_menu(cls, page, name="new menu"):
     """
     This function creates a menu.
     """
     db = Database()
     menu = Menu()
     menu.set_id(db.get_seq_next('MNU_GEN'))
     menu.set_name(name)
     stmnt = "INSERT INTO MENUS (MNU_ID,MNU_NAME, MNU_SIT_ID) VALUES (?,?, ?) ;"
     db.query(stmnt, (menu.get_id(), menu.get_name(), page.get_id()),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
     return menu 
예제 #22
0
파일: action.py 프로젝트: skarphed/skarphed
 def set_parent_menu_item_id(self, parent_menu_item_id, ignore_db=False):
     """
     Assigns this MenuItem to a parent MenuItem
     Resets any relations this MenuItem has to a Menu
     """
     self._parent_menu_item_id = parent_menu_item_id
     self._menu = None
     self._menu_id = None
     if self.get_id() is not None and not ignore_db:
         db = Database()
         stmnt = "UPDATE MENUITEMS SET MNI_MNI_ID = ?, MNI_MNU_ID = NULL WHERE MNI_ID = ? ;"
         db.query(stmnt, (self._parent_menu_item_id, self.get_id()),commit=True)
         PokeManager.add_activity(ActivityType.MENU)
예제 #23
0
    def store(self):
        """
        stores the template information in the database
        """
        db = Database()
        stmnt = "UPDATE OR INSERT INTO TEMPLATE_INFO (TPL_ID, TPL_NAME, TPL_DESC, TPL_AUTHOR) \
                 VALUES (0, ?, ?, ? ) MATCHING (TPL_ID) ;"
        db.query(stmnt, (self._name, self._description, self._author), commit=True)

        stmnt = "INSERT INTO TEMPLATE_BINARIES (TPB_TPL_ID, TPB_BIN_ID) VALUES (?,?) ;"
        for bin_id in self._binaries:
            db.query(stmnt, (0, bin_id), commit=True)
        PokeManager.add_activity(ActivityType.TEMPLATE)
예제 #24
0
    def remove_permission(self, permission):
        """
        removes a given permission from this role
        """
        session_user = Session.get_current_session_user()
        
        if not session_user.check_permission(permission):
            raise PermissionException(PermissionException.get_msg(3))

        db = Database()
        stmnt = "DELETE FROM ROLERIGHTS WHERE RRI_ROL_ID = ? AND RRI_RIG_ID = (SELECT RIG_ID FROM RIGHTS WHERE RIG_NAME = ?); "
        db.query(stmnt,(self._id,permission),commit=True)
        PokeManager.add_activity(ActivityType.ROLE)
예제 #25
0
파일: action.py 프로젝트: skarphed/skarphed
 def remove_action(self,action):
     """
     Removes the given action from the ActionList
     Only does something if the given action is present in 
     this ActionList
     """
     for child in self._children:
         if child.get_id() == action.get_id():
             self._children.remove(child)
             break
     db = Database()
     stmnt = "UPDATE ACTIONS SET ACT_ATL_ID = NULL WHERE ACT_ID = ? ;"
     db.query(stmnt, (action.get_id(),),commit=True)
     PokeManager.add_activity(ActivityType.MENU)
예제 #26
0
파일: action.py 프로젝트: skarphed/skarphed
    def create_action(cls, actionlist=None, view_id=None, url=None, widget_id = None, space_id = None):
        """
        This method creates a new Action and returns it.
        You can create an action based on either:
        1. A Page Id 
        2. An URL
        3. A widgetId combined with a SpaceId (Both applies to the site the menu is showed in)
        If the combination is not valid this function will return null and not do anything in db
        The action will be inserted with the lowest order (execution priority)
        """
        if actionlist is None:
            return None
        action = Action()
        action.set_action_list_id(actionlist.get_id())
        if view_id is not None:
            view = View.get_from_id(view_id)
            if view is not None:
                action.set_view_id(view_id)
            else:
                return None
        elif url is not None:
            action.set_url(str(url),True)
        elif widget_id is not None and space_id is not None:
            widget = ModuleManager.get_widget(widget_id)
            if widget is not None:
                action.set_widget_space_constellation(widget_id,space_id,True)
        else:
            return None

        action.set_name("new action",True)
        db = Database()
        new_id = db.get_seq_next("ACT_GEN")
        stmnt = "SELECT MAX(ACT_ORDER) AS MAXORDER FROM ACTIONS WHERE ACT_ATL_ID = ? ;"
        cur = db.query(stmnt, (action.get_action_list_id(),))
        row = cur.fetchonemap()
        if row["MAXORDER"] is not None:
            new_order = row["MAXORDER"]+1
        else:
            new_order = 0
        action.set_id(new_id)
        action.set_order(new_order)
        stmnt = "INSERT INTO ACTIONS (ACT_ID, ACT_NAME, ACT_ATL_ID, \
                                      ACT_VIE_ID, ACT_SPA_ID, ACT_WGT_ID, ACT_URL, ACT_ORDER) \
                              VALUES (?,?,?,?,?,?,?,?) ;"
        db.query(stmnt, (action.get_id(), action.get_name(), action.get_action_list_id(),
                                     action.get_view_id(), action.get_space(), action.get_widget_id(),
                                     action.get_url(), action.get_order()),commit=True)
        PokeManager.add_activity(ActivityType.MENU)
        return action
예제 #27
0
    def add_permission(self, permission):
        """
        adds a given permission to this role
        """
        session_user = Session.get_current_session_user()

        if not session_user.check_permission(permission):
            raise PermissionException(PermissionException.get_msg(3))

        db = Database()
        stmnt = "UPDATE OR INSERT INTO ROLERIGHTS (RRI_ROL_ID, RRI_RIG_ID) \
                        VALUES (?, (SELECT RIG_ID FROM RIGHTS WHERE RIG_NAME= ?)) \
                      MATCHING (RRI_ROL_ID, RRI_RIG_ID);";
        db.query(stmnt,(self._id, permission),commit=True)
        PokeManager.add_activity(ActivityType.ROLE)
예제 #28
0
    def store(self):
        """
        Stores the current state of the role into the database
        """
        if self._id is None:
            raise PermissionException(PermissionException.get_msg(0))

        if self._name == "":
            raise PermissionException(PermissionException.get_msg(1))


        db = Database()
        stmnt = "UPDATE OR INSERT INTO ROLES (ROL_ID, ROL_NAME) VALUES (?,?) MATCHING (ROL_ID) ;"
        db.query(stmnt,(self._id,self._name),commit=True)
        PokeManager.add_activity(ActivityType.ROLE)
예제 #29
0
파일: action.py 프로젝트: skarphed/skarphed
    def set_url(self, url, ignore_db=False):
        """
        Make this Action an URL-Operation
        Resets Widget/Space or Site-attributes of this Action
        """
        self._url = url
        self._widget_id = None
        self._space_id = None
        self._view_id = None

        if not ignore_db:
            db = Database()
            stmnt = "UPDATE ACTIONS SET ACT_URL = ?, ACT_VIE_ID = NULL, \
                     ACT_WGT_ID = NULL, ACT_SPA_ID = NULL WHERE ACT_ID = ?;"
            db.query(stmnt, (self.get_url(),self.get_id()),commit=True)
            PokeManager.add_activity(ActivityType.MENU)
예제 #30
0
파일: action.py 프로젝트: skarphed/skarphed
    def add_action(self,action):
        """
        This function adds an Action to this ActionList
        if $action is an integer, it will be handled as actionId
        the action will only be added if it is not already a part
        of this ActionList
        """
        if type(action) == int:
            action = Action.get_action_by_id(action)

        if action is not None and action not in self._children:
            self._children.append(action)
            db = Database()
            stmnt = "UPDATE ACTIONS SET ACT_ATL_ID = ? WHERE ACT_ID = ? ;"
            db.query(stmnt, (self.get_id(),action.get_id()),commit=True)
            PokeManager.add_activity(ActivityType.MENU)