Ejemplo n.º 1
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 == 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 == 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()

            #Initialize lookup values
            initLookups()
Ejemplo n.º 2
0
    def CheckAccess(self, contentCode):
        '''
        Assert whether the given user has permissions to access a content
        item with the gien code.
        '''
        hasPermission = False

        #Get roles with permission
        try:
            cnt = Content()
            qo = cnt.queryObject()
            cntRef = qo.filter(Content.code == contentCode).first()

            if cntRef != None:
                cntRoles = cntRef.roles
                for rl in cntRoles:
                    if getIndex(self.userRoles,rl.name) != -1:
                        hasPermission = True
                        break
        except Exception:
            '''
            Current user does not have permission to access the content tables.
            Catches all errors
            '''
            #pass
            raise

        return hasPermission
Ejemplo n.º 3
0
    def contentItemFromQAction(qAction):
        """
        Creates a Content object from a QAction object.
        """
        cnt = Content()
        cnt.name = qAction.text()

        return cnt
Ejemplo n.º 4
0
 def loadContent(self):
     '''
     Loads STDM content items
     '''
     self.content = Content()
     cntItems = self.content.queryObject().all()
     cnts = [cntItem.name for cntItem in cntItems]
     self.contentModel = UsersRolesModel(cnts)        
     self.lstContent.setModel(self.contentModel)
Ejemplo n.º 5
0
    def addContent(self, name, code):
        """
        Create a new Content item and add it to the collection.
        """
        cnt = Content()
        cnt.name = name
        cnt.code = code

        self._contentItems.append(cnt)
Ejemplo n.º 6
0
    def _createDbOpContent(self):
        """
        Create content for database operations.
        The code for each content needs to be set by the caller.
        """
        self._createCnt = Content()
        self._createCnt.name = self._buildName(self.create_op)
        self.addContentItem(self._createCnt)

        self._readCnt = Content()
        self._readCnt.name = self._buildName(self.read_op)
        self.addContentItem(self._readCnt)

        self._updateCnt = Content()
        self._updateCnt.name = self._buildName(self.update_op)
        self.addContentItem(self._updateCnt)

        self._deleteCnt = Content()
        self._deleteCnt.name = self._buildName(self.delete_op)
        self.addContentItem(self._deleteCnt)
Ejemplo n.º 7
0
    def _getEditPermissions(self):
        '''
        Returns True/False whether the current logged in user has permissions to create new social tenure relationships.
        If true, then the system assumes that they can also edit STR records.
        '''
        canEdit = False
        userName = stdm.data.app_dbconn.User.UserName
        authorizer = Authorizer(userName)
        newSTRCode = "9576A88D-C434-40A6-A318-F830216CA15A"

        #Get the name of the content from the code
        cnt = Content()
        createSTRCnt = cnt.queryObject().filter(
            Content.code == newSTRCode).first()
        if createSTRCnt:
            name = createSTRCnt.name
            canEdit = authorizer.CheckAccess(name)

        return canEdit