Implementation of basic permission checks.
parent
2c49209b8e
commit
96685d2bed
@ -0,0 +1,43 @@
|
||||
#include "permissionevaluator.h"
|
||||
|
||||
#include <QSharedPointer>
|
||||
|
||||
#include "data/core-data.h"
|
||||
#include "context.h"
|
||||
|
||||
PermissionEvaluator::PermissionEvaluator(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PermissionEvaluator::~PermissionEvaluator()
|
||||
{
|
||||
}
|
||||
|
||||
bool PermissionEvaluator::hasPermission(const QString &pluginId, const QString &permission)
|
||||
{
|
||||
if (Context::instance().currentUser()->isAdmin())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ret;
|
||||
QList<QSharedPointer<Role> > roles = Context::instance().currentUser()->listRoles();
|
||||
|
||||
ret = std::find_if(ALL(roles), [&pluginId, &permission](QSharedPointer<Role> role) -> bool {
|
||||
foreach (QSharedPointer<Permission> perm, role->listPermissions()) {
|
||||
if (perm->pluginId() == pluginId && perm->permissionName() == permission) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}) != roles.end();
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
emit permissionDenied(permission);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
#ifndef PERMISSIONEVALUATOR_H
|
||||
#define PERMISSIONEVALUATOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#include "core_global.h"
|
||||
|
||||
class CORESHARED_EXPORT PermissionEvaluator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PermissionEvaluator(QObject *parent = NULL);
|
||||
~PermissionEvaluator();
|
||||
|
||||
bool hasPermission(const QString &pluginId, const QString &permission);
|
||||
|
||||
signals:
|
||||
void permissionDenied(QString permission);
|
||||
};
|
||||
|
||||
#endif // PERMISSIONEVALUATOR_H
|
Loading…
Reference in New Issue