Implemented permission settings for Roles.
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "rolesform.h"
|
||||
#include "ui_rolesform.h"
|
||||
#include "iplugin.h"
|
||||
#include "permissionservice.h"
|
||||
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
RolesForm::RolesForm(QWidget *parent) :
|
||||
AutoForm<Role>(parent),
|
||||
@@ -15,3 +19,53 @@ RolesForm::~RolesForm()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void RolesForm::bindOtherToUi()
|
||||
{
|
||||
ui->treePerms->clear();
|
||||
QList<QSharedPointer<Permission> > perms = entity()->listPermissions();
|
||||
|
||||
foreach (IPlugin *plugin, Context::instance().plugins()) {
|
||||
if (plugin->pluginId() != "CORE")
|
||||
{
|
||||
QTreeWidgetItem *item = new QTreeWidgetItem();
|
||||
item->setText(0, plugin->pluginName());
|
||||
item->setData(0, Qt::UserRole, plugin->pluginId());
|
||||
|
||||
foreach (QString perm, Context::instance().defaultPerms()) {
|
||||
QTreeWidgetItem *permItem = new QTreeWidgetItem();
|
||||
permItem->setText(0, tr(perm.toStdString().c_str()));
|
||||
permItem->setData(0, Qt::UserRole, perm);
|
||||
QList<QSharedPointer<Permission> >::iterator it = std::find_if(ALL(perms), [&perm, plugin](QSharedPointer<Permission> p){ return p->permissionName() == perm
|
||||
&& p->pluginId() == plugin->pluginId(); });
|
||||
permItem->setCheckState(0, it != perms.end() ? Qt::Checked : Qt::Unchecked);
|
||||
item->addChild(permItem);
|
||||
}
|
||||
ui->treePerms->addTopLevelItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool RolesForm::bindOtherToData()
|
||||
{
|
||||
PermissionService permService;
|
||||
|
||||
entity()->clearPermissions();
|
||||
for (int i = 0; i < ui->treePerms->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem *item = ui->treePerms->topLevelItem(i);
|
||||
|
||||
for (int j = 0; j < item->childCount(); j++)
|
||||
{
|
||||
QTreeWidgetItem *permItem = item->child(j);
|
||||
if (permItem->checkState(0) == Qt::Checked)
|
||||
{
|
||||
QSharedPointer<Permission> perm = permService.forNameAndPlugin(permItem->data(0, Qt::UserRole).toString(), item->data(0, Qt::UserRole).toString());
|
||||
perm->addRole(entity());
|
||||
entity()->addPermission(perm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,11 @@ public:
|
||||
|
||||
private:
|
||||
Ui::RolesForm *ui;
|
||||
|
||||
// AutoForm interface
|
||||
protected:
|
||||
virtual void bindOtherToUi() override;
|
||||
virtual bool bindOtherToData() override;
|
||||
};
|
||||
|
||||
#endif // ROLESFORM_H
|
||||
|
||||
+24
-2
@@ -7,13 +7,16 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>542</width>
|
||||
<height>388</height>
|
||||
<height>270</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
@@ -24,13 +27,32 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="name"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="active">
|
||||
<property name="text">
|
||||
<string>Active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QTreeWidget" name="treePerms">
|
||||
<attribute name="headerVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Permissions:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
Reference in New Issue
Block a user