Fixed some minor issues
This commit is contained in:
+41
-14
@@ -93,6 +93,7 @@ GroupManager::GroupManager(const shared_ptr<VirtualServer> &server, sql::SqlMana
|
||||
GroupManager::~GroupManager() {}
|
||||
|
||||
bool GroupManager::loadGroupFormDatabase(GroupId id) {
|
||||
std::lock_guard glock{this->group_lock};
|
||||
if(id == 0){
|
||||
this->groups.clear();
|
||||
|
||||
@@ -116,8 +117,13 @@ bool GroupManager::loadGroupFormDatabase(GroupId id) {
|
||||
|
||||
std::vector<std::shared_ptr<Group>> GroupManager::availableGroups(bool root) {
|
||||
std::vector<std::shared_ptr<Group>> response;
|
||||
for(const auto& group : this->groups)
|
||||
response.push_back(group);
|
||||
|
||||
{
|
||||
std::lock_guard glock{this->group_lock};
|
||||
for(const auto& group : this->groups)
|
||||
response.push_back(group);
|
||||
}
|
||||
|
||||
if(root && this->root){
|
||||
auto elm = this->root->availableGroups();
|
||||
for(const auto& e : elm)
|
||||
@@ -128,9 +134,14 @@ std::vector<std::shared_ptr<Group>> GroupManager::availableGroups(bool root) {
|
||||
|
||||
std::vector<std::shared_ptr<Group>> GroupManager::availableServerGroups(bool root){
|
||||
std::vector<std::shared_ptr<Group>> response;
|
||||
for(const auto& group : this->groups)
|
||||
if(group->target() == GroupTarget::GROUPTARGET_SERVER)
|
||||
response.push_back(group);
|
||||
|
||||
{
|
||||
std::lock_guard glock{this->group_lock};
|
||||
for(const auto& group : this->groups)
|
||||
if(group->target() == GroupTarget::GROUPTARGET_SERVER)
|
||||
response.push_back(group);
|
||||
}
|
||||
|
||||
if(root && this->root){
|
||||
auto elm = this->root->availableServerGroups();
|
||||
for(const auto& e : elm)
|
||||
@@ -141,9 +152,12 @@ std::vector<std::shared_ptr<Group>> GroupManager::availableServerGroups(bool roo
|
||||
|
||||
std::vector<std::shared_ptr<Group>> GroupManager::availableChannelGroups(bool root) {
|
||||
std::vector<std::shared_ptr<Group>> response;
|
||||
for(const auto& group : this->groups)
|
||||
if(group->target() == GroupTarget::GROUPTARGET_CHANNEL)
|
||||
response.push_back(group);
|
||||
{
|
||||
std::lock_guard glock{this->group_lock};
|
||||
for(const auto& group : this->groups)
|
||||
if(group->target() == GroupTarget::GROUPTARGET_CHANNEL)
|
||||
response.push_back(group);
|
||||
}
|
||||
if(root && this->root){
|
||||
auto elm = this->root->availableChannelGroups(true);
|
||||
for(const auto& e : elm)
|
||||
@@ -236,6 +250,7 @@ void GroupManager::handleChannelDeleted(const ChannelId& channel_id) {
|
||||
}
|
||||
|
||||
bool GroupManager::isLocalGroup(std::shared_ptr<Group> gr) {
|
||||
std::lock_guard glock{this->group_lock};
|
||||
return std::find(this->groups.begin(), this->groups.end(), gr) != this->groups.end();
|
||||
}
|
||||
|
||||
@@ -251,9 +266,12 @@ std::shared_ptr<Group> GroupManager::defaultGroup(GroupTarget type, bool enforce
|
||||
auto group = this->findGroupLocal(id);
|
||||
if(group || enforce_property) return group;
|
||||
|
||||
for(auto elm : this->groups)
|
||||
if(elm->target() == type)
|
||||
return elm;
|
||||
{
|
||||
std::lock_guard glock{this->group_lock};
|
||||
for(auto elm : this->groups)
|
||||
if(elm->target() == type)
|
||||
return elm;
|
||||
}
|
||||
|
||||
return nullptr; //Worst case!
|
||||
}
|
||||
@@ -265,6 +283,7 @@ std::shared_ptr<Group> GroupManager::findGroup(GroupId groupId) {
|
||||
}
|
||||
|
||||
std::shared_ptr<Group> GroupManager::findGroupLocal(GroupId groupId) {
|
||||
std::lock_guard glock{this->group_lock};
|
||||
for(const auto& elm : this->groups)
|
||||
if(elm->groupId() == groupId) return elm;
|
||||
return nullptr;
|
||||
@@ -272,8 +291,11 @@ std::shared_ptr<Group> GroupManager::findGroupLocal(GroupId groupId) {
|
||||
|
||||
std::vector<std::shared_ptr<Group>> GroupManager::findGroup(GroupTarget target, std::string name) {
|
||||
vector<shared_ptr<Group>> res;
|
||||
for(const auto &elm : this->groups)
|
||||
if(elm->name() == name && elm->target() == target) res.push_back(elm);
|
||||
{
|
||||
std::lock_guard glock{this->group_lock};
|
||||
for(const auto &elm : this->groups)
|
||||
if(elm->name() == name && elm->target() == target) res.push_back(elm);
|
||||
}
|
||||
if(this->root) {
|
||||
auto r = root->findGroup(target, name);
|
||||
for(const auto &e : r) res.push_back(e);
|
||||
@@ -304,6 +326,8 @@ std::shared_ptr<Group> GroupManager::createGroup(GroupTarget target, GroupType t
|
||||
std::shared_ptr<Group> group = std::make_shared<Group>(this, target, type, groupId);
|
||||
group->properties()[property::GROUP_NAME] = name;
|
||||
group->setPermissionManager(serverInstance->databaseHelper()->loadGroupPermissions(this->server.lock(), group->groupId()));
|
||||
|
||||
std::lock_guard glock{this->group_lock};
|
||||
this->groups.push_back(group);
|
||||
return group;
|
||||
}
|
||||
@@ -393,7 +417,10 @@ bool GroupManager::deleteGroup(std::shared_ptr<Group> group) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this->groups.erase(std::find(this->groups.begin(), this->groups.end(), group));
|
||||
{
|
||||
std::lock_guard glock{this->group_lock};
|
||||
this->groups.erase(std::find(this->groups.begin(), this->groups.end(), group));
|
||||
}
|
||||
|
||||
/* erase the group out of our cache */
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user