aboutsummaryrefslogtreecommitdiff
path: root/src/User.cpp
blob: 58e350ae7f4e4caacc7614f8579cb19e70a626c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "../include/odhtdb/User.hpp"
#include "../include/odhtdb/Group.hpp"

namespace odhtdb
{
    User::User(Type _type, const std::string &_name, Group *group) : type(_type), name(_name)
    {
        if(name.size() > 255)
            throw UserNameTooLongException(name);
        addToGroup(group);
    }
    
    User::~User()
    {
        for(Group *group : groups)
        {
            group->removeUser(this);
        }
    }
    
    void User::addToGroup(Group *group)
    {
        if(group)
        {
            groups.emplace_back(group);
            group->addUser(this);
        }
    }
    
    bool User::isAllowedToPerformAction(PermissionType action) const
    {
        for(Group *group : getGroups())
        {
            if(group->getPermission().getFlag(action))
                return true;
        }
        return false;
    }
}