You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1013 B
C++
44 lines
1013 B
C++
#include "permissionevaluator.h"
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include "data/core-data.h"
|
|
#include "context.h"
|
|
|
|
PermissionEvaluator::PermissionEvaluator(QObject *parent)
|
|
:QObject(parent)
|
|
{
|
|
}
|
|
|
|
bool PermissionEvaluator::hasPermission(const QString &pluginId, const QString &permission)
|
|
{
|
|
if (!Context::instance().currentUser()) {
|
|
return false;
|
|
}
|
|
|
|
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](const 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;
|
|
}
|
|
|