def loadRoles(self,contentname = ""): ''' Loads the roles in the database cluster ''' self.roleProvider = RoleProvider() sysRoles = self.roleProvider.GetAllRoles() roles = [] #Load the corresponding roles for the specified content item if contentname != "": self.currentContent = self.content.queryObject().filter(Content.name == contentname).first() if self.currentContent: roles = [rl.name for rl in self.currentContent.roles] #Initialize model self.roleMappingsModel = QStandardItemModel(self) self.roleMappingsModel.setColumnCount(1) #Add role items into the standard item model for r in range(len(sysRoles)): role = sysRoles[r] if role.name != "postgres": roleItem = self._createNewRoleItem(role.name) #Check if the db role is in the approved for the current content item roleIndex = getIndex(roles,role.name) if roleIndex != -1: roleItem.setCheckState(Qt.Checked) self.roleMappingsModel.appendRow(roleItem) self.lstRoles.setModel(self.roleMappingsModel)
def acceptdlg(self): ''' On user clicking the create user button ''' if self.validateInput(): roleProvider = RoleProvider() try: #Create new or update user if self.role == None: self._setRole() #Update the db cluster roles as well roleProvider.CreateRole(self.role.name, self.role.description) roleProvider.AddSTDMRole(self.role.name, self.role.description) self.accept() except SecurityException as se: QMessageBox.critical( self, QApplication.translate("newUserDlg", "Create New User Error"), str(se)) self.user = None except sqlalchemy.exc.ProgrammingError as pe: QMessageBox.critical( self, QApplication.translate("newUserDlg", "Create New User Error"), str(pe.message)) self.user = None