First permissions restriction
This commit is contained in:
parent
60c8782bdd
commit
f03f392cee
6 changed files with 34 additions and 13 deletions
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "actor.h"
|
||||
|
||||
Module::Actor::Actor(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection):
|
||||
Module(core, connection)
|
||||
Module::Actor::Actor(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection, const Permissions& permissions):
|
||||
Module(core, connection, permissions)
|
||||
{}
|
||||
|
||||
Module::Actor::~Actor() noexcept {}
|
||||
|
@ -13,7 +13,7 @@ void Module::Actor::message(const std::shared_ptr<::Actor>& actor, const Module:
|
|||
std::string result;
|
||||
|
||||
if (args.front() == "list")
|
||||
result = list();
|
||||
result = hasPermission("read", actor) ? list() : "Can not tell you that";
|
||||
|
||||
if (!result.empty())
|
||||
connection->send(actor->jid, result);
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Module {
|
|||
|
||||
class Actor : public Module {
|
||||
public:
|
||||
Actor(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection);
|
||||
Actor(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection, const Permissions& permissions);
|
||||
~Actor() noexcept;
|
||||
|
||||
virtual void message(const std::shared_ptr<::Actor>& actor, const Tokens& args) override;
|
||||
|
|
|
@ -3,13 +3,24 @@
|
|||
|
||||
#include "module.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "gloox/message.h"
|
||||
|
||||
Module::Module::Module(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection):
|
||||
Module::Module::Module(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection, const Permissions& permissions):
|
||||
core(core),
|
||||
connection(connection)
|
||||
connection(connection),
|
||||
permissions(permissions)
|
||||
{}
|
||||
|
||||
bool Module::Module::hasPermission(const std::string& permission, const std::shared_ptr<::Actor>& actor) const {
|
||||
Permissions::const_iterator itr = permissions.find(permission);
|
||||
if (itr == permissions.end())
|
||||
return false;
|
||||
|
||||
return std::find(itr->second.begin(), itr->second.end(), actor->getGroup()) != itr->second.end();
|
||||
}
|
||||
|
||||
Module::Module::~Module() noexcept {}
|
||||
|
||||
std::vector<std::string> Module::Module::split(const std::string& string, const std::string& delimiter) {
|
||||
|
|
|
@ -16,20 +16,25 @@ namespace Module {
|
|||
class Module {
|
||||
public:
|
||||
typedef std::vector<std::string> Tokens;
|
||||
typedef std::vector<std::string> List;
|
||||
typedef std::map<std::string, List> Permissions;
|
||||
|
||||
protected:
|
||||
Module(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection);
|
||||
Module(const std::shared_ptr<Core>& core, const std::shared_ptr<Connection>& connection, const Permissions& permissions);
|
||||
|
||||
bool hasPermission(const std::string& permission, const std::shared_ptr<::Actor>& actor) const;
|
||||
|
||||
public:
|
||||
virtual ~Module() noexcept;
|
||||
|
||||
static Tokens split(const std::string& string, const std::string& delimiter = " ");
|
||||
|
||||
virtual void message(const std::shared_ptr<Actor>& actor, const Tokens& args) = 0;
|
||||
virtual void message(const std::shared_ptr<::Actor>& actor, const Tokens& args) = 0;
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Core> core;
|
||||
std::shared_ptr<Connection> connection;
|
||||
Permissions permissions;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue