示例#1
0
 def GetRole(self, rolename):
     '''
     Get the STDM role object based on the rolename
     '''
     rl = Role()
     role = rl.queryObject().filter(Role.name == rolename).first()
     return role
示例#2
0
 def GetAllRoles(self):
     '''
     Get all the roles objects in the database server
     '''
     rl = Role()
     qo = rl.queryObject()
     return qo.all()
示例#3
0
    def onRoleSelected(self, index):
        '''
        Slot which is called when a user checks/unchecks to add/remove a role for the 
        specified content item.
        '''
        if self.currentContent != None:

            item = self.roleMappingsModel.itemFromIndex(index)
            rolename = item.text()

            self.privilege_provider.role = rolename

            #Get role object from role name
            role = Role()
            rl = role.queryObject().filter(Role.name == rolename).first()

            self.blockSignals(True)

            #Add role to the content item if the item is selected  or remove if it was previosuly checked
            if item.checkState() == Qt.Checked:
                self.currentContent.roles.append(rl)
                self.privilege_provider.grant_privilege()

            elif item.checkState() == Qt.Unchecked:
                self.currentContent.roles.remove(rl)
                self.privilege_provider.revoke_privilege()

            self.currentContent.update()

            self.blockSignals(False)
示例#4
0
    def register(self):
        """
        Registers the content items into the database. Registration only works for a 
        postgres user account.
        """
        pg_account = "postgres"

        if self._username == pg_account:
            for c in self.contentItems():
                if isinstance(c, Content):
                    cnt = Content()
                    qo = cnt.queryObject()
                    cn = qo.filter(Content.code == c.code).first()

                    #If content not found then add
                    if cn is None:
                        #Check if the 'postgres' role is defined, if not then create one
                        rl = Role()
                        rolequery = rl.queryObject()
                        role = rolequery.filter(
                            Role.name == pg_account).first()

                        if role is None:
                            rl.name = pg_account
                            rl.contents = [c]
                            rl.save()
                        else:
                            existingContents = role.contents
                            #Append new content to existing
                            existingContents.append(c)
                            role.contents = existingContents
                            role.update()
示例#5
0
 def DeleteSTDMRole(self, rolename):
     '''
     Delete STDM role
     '''
     rl = Role()
     existRole = rl.queryObject().filter(Role.name == rolename).first()
     if existRole != None:
         existRole.delete()
示例#6
0
 def AddSTDMRole(self, rolename, description=""):
     '''
     Add role to STDM roles table
     '''
     rl = Role()
     existRole = rl.queryObject().filter(Role.name == rolename).first()
     if existRole == None:
         rl.name = rolename
         rl.description = description
         rl.save()
示例#7
0
    def _setRole(self):
        '''
        Create/update the user object based on the user input
        '''
        roleName = self.txtRoleName.text()
        roleDescription = self.txtRoleDescription.text()

        if self.role == None:
            self.role = Role()
            self.role.name = roleName
            self.role.description = string.strip(roleDescription)
示例#8
0
    def register(self):
        """
        Registers the content items into the database. Registration only works for a 
        postgres user account.
        """
        PG_ACCOUNT = "postgres"

        if self._username == PG_ACCOUNT:
            for c in self.contentItems():
                if isinstance(c, Content):
                    cnt = Content()
                    qo = cnt.queryObject()

                    if c.code is None:
                        code = self.hash_code(unicode(c.name))
                        cn = c
                    else:
                        code = c.code

                    cn = qo.filter(Content.code == code).first()

                    #If content not found then add
                    if cn is None:
                        #Check if the 'postgres' role is defined, if not then create one
                        rl = Role()
                        rolequery = rl.queryObject()
                        role = rolequery.filter(
                            Role.name == PG_ACCOUNT).first()

                        if role is None:
                            rl.name = PG_ACCOUNT
                            rl.contents = [c]
                            rl.save()
                        else:
                            existingContents = role.contents
                            #Append new content to existing
                            if c.code is None:
                                c.code = code

                            if len([
                                    e_cont for e_cont in existingContents
                                    if e_cont.name == c.name
                            ]) == 0:
                                existingContents.append(c)
                                role.contents = existingContents
                                role.update()
        else:
            for c in self.contentItems():
                if isinstance(c, Content):
                    cnt = Content()
                    qo = cnt.queryObject()
                    cn = qo.filter(Content.name == c.name).first()
                    c.code = cn.code