示例#1
0
    def handleRemovePerm(self):
        groupName = str(self.LST_groups.selectedItems()[0].text())
        pg = PermissionGroup.fromPk(groupName)

        if pg is None:
            QMessageBox(QMessageBox.Warning,
                        'Remove Permission Error',
                        '{} doesn\'t exist'.format(groupName),
                        buttons=QMessageBox.Ok,
                        parent=self).exec_()
            return
        elif self.LST_perms.count() > 0:
            permList = pg.permissionList

            if len(permList) == 1:
                # Don't allow people to remove the last perm node the group has
                QMessageBox(
                    QMessageBox.Warning,
                    'Remove Permission Error',
                    'Cannot remove a permission if it is the group\'s only one',
                    buttons=QMessageBox.Ok,
                    parent=self).exec_()
            else:
                perm = str(
                    self.LST_perms.takeItem(
                        self.LST_perms.currentRow()).text())
                permList.pop(permList.index(perm))
                pg.permissionList = permList
                pg.set('perm_nodes', pg.perm_nodes)
示例#2
0
    def handleGroupChange(self):
        selected = self.LST_groups.selectedItems()

        if len(selected) == 1:
            groupName = str(selected[0].text())
            pg = PermissionGroup.fromPk(groupName)

            if not pg:
                raise KeyError(
                    'Permission group {} is not defined'.format(groupName))

            self.LST_users.clear()
            self.LST_perms.clear()
            self.GRP_users.setEnabled(True)
            self.BTN_removeGroup.setEnabled(True)

            for user in hxdb.getUsers():
                if user.perm_group == groupName:
                    self.LST_users.addItem(user.username)

                if groupName == 'defaultgroup':
                    # self.LST_users.addItem('Users who are not in a group are considered a part of this one')
                    self.GRP_users.setEnabled(False)
                    self.BTN_removeGroup.setEnabled(False)

            for perm in pg.permissionList:
                self.LST_perms.addItem(perm)
        else:
            # Clear the users in group and permissions lists
            self.LST_users.clear()
            self.LST_perms.clear()
            self.BTN_removeGroup.setEnabled(False)
示例#3
0
    def handleRemoveGroup(self):
        selected = self.LST_groups.selectedItems()
        groupName = str(selected[0].text())

        if groupName == 'defaultgroup':
            # Should be impossible, but just in case you know...
            QMessageBox(
                QMessageBox.Warning,
                'Remove Group Error',
                'Can\'t delete defaultgroup, it must always be defined!',
                buttons=QMessageBox.Ok,
                parent=self).exec_()
            return

        pg = PermissionGroup.fromPk(groupName)

        if pg is None:
            QMessageBox(QMessageBox.Warning,
                        'Remove Group Error',
                        '{} doesn\'t exist'.format(groupName),
                        buttons=QMessageBox.Ok,
                        parent=self).exec_()
            return
        else:
            self.LST_groups.takeItem(self.LST_groups.currentRow())
            pg.delete()
示例#4
0
    def __init__(self, username, full_name=None, department=None, dummy=False):
        self.table = Person.TABLE
        self.username = username
        self._exists = None

        if dummy:
            return

        if len(self.username) > 10:
            raise ValueError('Username cannot be longer than 10 characters')

        fetched = self.exists(fetch=True)

        if fetched:
            self.unmap(fetched)
            self._exists = True
        else:
            self._exists = False
            self.full_name = full_name

            if not department:
                department = 'general'

            self.department = department.lower()

            from helix.environment.permissions import PermissionGroup

            # Create the default group right away if it doesn't exist
            # otherwise, we can't insert the user into the database with that group
            defGroup = PermissionGroup(PermissionGroup.DEFAULT,
                                       permissions=['helix.*'])

            if not defGroup.exists():
                defGroup.insert()

            self.perm_group = PermissionGroup.DEFAULT

            if self.department not in env.cfg.departments and self.department != 'general':
                raise ValueError(
                    'Not a valid department ({}). Options are: {}'.format(
                        self.department,
                        ', '.join(['general'] + env.cfg.departments)))
示例#5
0
    def handleAddGroup(self):
        dialog = QDialog(self)
        layout = QVBoxLayout()
        groupName = QLineEdit(dialog)
        buttonLayout = QHBoxLayout()
        cancel = QPushButton('Cancel')
        create = QPushButton('Create')

        cancel.clicked.connect(dialog.reject)
        create.clicked.connect(dialog.accept)
        create.setDefault(True)

        layout.addWidget(groupName)
        buttonLayout.addWidget(cancel)
        buttonLayout.addWidget(create)
        buttonLayout.insertStretch(0)
        layout.addLayout(buttonLayout)
        dialog.setWindowTitle('Create Group')
        dialog.setLayout(layout)

        if dialog.exec_() == QDialog.Accepted:
            name = str(groupName.text()).strip()

            if name:
                pg = PermissionGroup(name)
                if pg.exists():
                    QMessageBox(
                        QMessageBox.Warning,
                        'Create Group Error',
                        'The group "{}" already exists, please select a different name.'
                        .format(name),
                        buttons=QMessageBox.Ok,
                        parent=self).exec_()
                    return

                pg.insert()
                self.LST_groups.addItem(name)
                self.LST_groups.setCurrentRow(self.LST_groups.count() - 1)
                self.handleGroupChange()
示例#6
0
    def handleAddPerm(self):
        dialog = QDialog(self)
        layout = QVBoxLayout()
        perm = QLineEdit(dialog)
        buttonLayout = QHBoxLayout()
        cancel = QPushButton('Cancel')
        create = QPushButton('Add')
        possibleNodes = PermissionNodes.expandedNodeList()
        completer = QCompleter(possibleNodes, perm)

        perm.setToolTip(
            'Permission nodes start with the "helix" prefix, begin typing to see available options.'
        )
        perm.setCompleter(completer)
        cancel.clicked.connect(dialog.reject)
        create.clicked.connect(dialog.accept)
        create.setDefault(True)

        layout.addWidget(perm)
        buttonLayout.addWidget(cancel)
        buttonLayout.addWidget(create)
        buttonLayout.insertStretch(0)
        layout.addLayout(buttonLayout)
        dialog.setWindowTitle('Add Permission Node')
        dialog.setLayout(layout)

        if dialog.exec_() == QDialog.Accepted:
            name = str(perm.text()).strip()
            group = str(self.LST_groups.selectedItems()[0].text())
            pg = PermissionGroup.fromPk(group)

            # Should also be impossible..
            if not pg:
                QMessageBox(QMessageBox.Warning,
                            'Group Error',
                            '{} doesn\'t exist'.format(group),
                            buttons=QMessageBox.Ok,
                            parent=self).exec_()
                return

            if name:
                if pg.permissionList and name in pg.permissionList:
                    QMessageBox(
                        QMessageBox.Warning,
                        'Add Permission Error',
                        'The permission "{}" already exists for the group "{}".'
                        .format(name, group),
                        buttons=QMessageBox.Ok,
                        parent=self).exec_()
                    return

                if name not in possibleNodes:
                    QMessageBox(
                        QMessageBox.Warning,
                        'Add Permission Error',
                        'Invalid permission node. Nodes begin with the prefix "helix" (or "^helix" for negated nodes), start typing to see all options.'
                        .format(name, group),
                        buttons=QMessageBox.Ok,
                        parent=self).exec_()
                    return

                permList = pg.permissionList
                permList.append(name)
                pg.permissionList = permList
                pg.set('perm_nodes', pg.perm_nodes)

                self.LST_perms.addItem(name)
                self.LST_perms.clearSelection()
                self.LST_perms.setCurrentRow(self.LST_perms.count() - 1)
示例#7
0
 def permGroup(self):
     from helix.environment.permissions import PermissionGroup
     return PermissionGroup.fromPk(self.perm_group)