fixed the default setup
This commit is contained in:
parent
05c3cab612
commit
c8a6449a45
@ -23,7 +23,7 @@ struct GroupInfo {
|
|||||||
* 2 = Channel
|
* 2 = Channel
|
||||||
*/
|
*/
|
||||||
int target;
|
int target;
|
||||||
string propertyName;
|
std::deque<string> properties;
|
||||||
string name;
|
string name;
|
||||||
/* permission type, value, granted, skip, negate */
|
/* permission type, value, granted, skip, negate */
|
||||||
deque<tuple<permission::PermissionType, permission::PermissionValue, permission::PermissionValue, bool, bool>> permissions;
|
deque<tuple<permission::PermissionType, permission::PermissionValue, permission::PermissionValue, bool, bool>> permissions;
|
||||||
@ -31,94 +31,94 @@ struct GroupInfo {
|
|||||||
|
|
||||||
/* TODO may use a transaction here? */
|
/* TODO may use a transaction here? */
|
||||||
bool InstanceHandler::setupDefaultGroups() {
|
bool InstanceHandler::setupDefaultGroups() {
|
||||||
debugMessage(LOG_INSTANCE, "Creating new instance groups");
|
debugMessage(LOG_INSTANCE, "Creating new instance groups");
|
||||||
deque<shared_ptr<GroupInfo>> groups;
|
deque<shared_ptr<GroupInfo>> groups;
|
||||||
|
|
||||||
ifstream in(PERMISSION_TEMPLATE_FILE);
|
ifstream in(PERMISSION_TEMPLATE_FILE);
|
||||||
if(!in) {
|
if(!in) {
|
||||||
logCritical(LOG_INSTANCE, "Could not open default permissions file {}", PERMISSION_TEMPLATE_FILE);
|
logCritical(LOG_INSTANCE, "Could not open default permissions file {}", PERMISSION_TEMPLATE_FILE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
string line;
|
string line;
|
||||||
while(getline(in, line)){
|
while(getline(in, line)){
|
||||||
TEST_COMMENT;
|
TEST_COMMENT;
|
||||||
|
|
||||||
if(line != "--start") {
|
if(line != "--start") {
|
||||||
logCritical(LOG_INSTANCE, R"(Permission template file contains invalid start line ("{}", expected "{}")!)", line, "--start");
|
logCritical(LOG_INSTANCE, R"(Permission template file contains invalid start line ("{}", expected "{}")!)", line, "--start");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto group = make_shared<GroupInfo>();
|
auto group = make_shared<GroupInfo>();
|
||||||
while(true){
|
while(true){
|
||||||
getline(in, line);
|
getline(in, line);
|
||||||
TEST_COMMENT;
|
TEST_COMMENT;
|
||||||
|
|
||||||
if(line == "--end") break;
|
if(line == "--end") break;
|
||||||
if(line.find("name:") == 0) {
|
if(line.find("name:") == 0) {
|
||||||
group->name = line.substr(5);
|
group->name = line.substr(5);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(line.find("target:") == 0) {
|
if(line.find("target:") == 0) {
|
||||||
group->target = stoi(line.substr(7));
|
group->target = stoi(line.substr(7));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(line.find("property:") == 0) {
|
if(line.find("property:") == 0) {
|
||||||
group->propertyName = line.substr(9);
|
group->properties.push_back(line.substr(9));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line.find("permission:") == 0) {
|
if(line.find("permission:") == 0) {
|
||||||
line = line.substr(11);
|
line = line.substr(11);
|
||||||
auto assign_index = line.find('=');
|
auto assign_index = line.find('=');
|
||||||
|
|
||||||
string permission_name = line.substr(0, assign_index);
|
string permission_name = line.substr(0, assign_index);
|
||||||
string string_value = line.substr(assign_index + 1);
|
string string_value = line.substr(assign_index + 1);
|
||||||
string string_granted, string_skip, string_negate;
|
string string_granted, string_skip, string_negate;
|
||||||
|
|
||||||
if(string_value.find(',') != -1) {
|
if(string_value.find(',') != -1) {
|
||||||
string_granted = string_value.substr(string_value.find(',') + 1);
|
string_granted = string_value.substr(string_value.find(',') + 1);
|
||||||
string_value = string_value.substr(0, string_value.find(','));
|
string_value = string_value.substr(0, string_value.find(','));
|
||||||
}
|
}
|
||||||
if(string_granted.find(',') != -1) {
|
if(string_granted.find(',') != -1) {
|
||||||
string_skip = string_granted.substr(string_granted.find(',') + 1);
|
string_skip = string_granted.substr(string_granted.find(',') + 1);
|
||||||
string_granted = string_granted.substr(0, string_granted.find(','));
|
string_granted = string_granted.substr(0, string_granted.find(','));
|
||||||
}
|
}
|
||||||
if(string_skip.find(',') != -1) {
|
if(string_skip.find(',') != -1) {
|
||||||
string_negate = string_skip.substr(string_skip.find(',') + 1);
|
string_negate = string_skip.substr(string_skip.find(',') + 1);
|
||||||
string_skip = string_skip.substr(0, string_skip.find(','));
|
string_skip = string_skip.substr(0, string_skip.find(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto permInfo = permission::resolvePermissionData(permission_name);
|
auto permInfo = permission::resolvePermissionData(permission_name);
|
||||||
if(permInfo->type == permission::unknown){
|
if(permInfo->type == permission::unknown){
|
||||||
logError(LOG_INSTANCE, "Default permission file contains unknown permission. Key: {}", permission_name);
|
logError(LOG_INSTANCE, "Default permission file contains unknown permission. Key: {}", permission_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
permission::PermissionValue permission_value;
|
permission::PermissionValue permission_value;
|
||||||
try {
|
try {
|
||||||
permission_value = stoi(string_value);
|
permission_value = stoi(string_value);
|
||||||
} catch(std::exception& ex) {
|
} catch(std::exception& ex) {
|
||||||
logError(LOG_INSTANCE, "Failed to parse value for key {}. Value: {}", permission_name, string_value);
|
logError(LOG_INSTANCE, "Failed to parse value for key {}. Value: {}", permission_name, string_value);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
permission::PermissionValue permission_granted = permNotGranted;
|
permission::PermissionValue permission_granted = permNotGranted;
|
||||||
if(!string_granted.empty()) {
|
if(!string_granted.empty()) {
|
||||||
try {
|
try {
|
||||||
permission_granted = stoi(string_granted);
|
permission_granted = stoi(string_granted);
|
||||||
} catch(std::exception& ex) {
|
} catch(std::exception& ex) {
|
||||||
logError(LOG_INSTANCE, "Failed to parse granted value for key {}. Value: {}", permission_name, string_granted);
|
logError(LOG_INSTANCE, "Failed to parse granted value for key {}. Value: {}", permission_name, string_granted);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flag_skip = string_skip == "true" || string_skip == "1";
|
bool flag_skip = string_skip == "true" || string_skip == "1";
|
||||||
bool flag_negate = string_negate == "true" || string_negate == "1";
|
bool flag_negate = string_negate == "true" || string_negate == "1";
|
||||||
|
|
||||||
group->permissions.emplace_back(make_tuple(permInfo->type, permission_value, permission_granted, flag_skip, flag_negate));
|
group->permissions.emplace_back(make_tuple(permInfo->type, permission_value, permission_granted, flag_skip, flag_negate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
groups.push_back(group);
|
groups.push_back(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
debugMessage(LOG_INSTANCE, "Read " + to_string(groups.size()) + " default groups");
|
debugMessage(LOG_INSTANCE, "Read " + to_string(groups.size()) + " default groups");
|
||||||
for(const auto& info : groups) {
|
for(const auto& info : groups) {
|
||||||
@ -132,16 +132,17 @@ bool InstanceHandler::setupDefaultGroups() {
|
|||||||
for(auto perm : info->permissions) {
|
for(auto perm : info->permissions) {
|
||||||
group->permissions()->set_permission(get<0>(perm), {get<1>(perm), get<2>(perm)}, permission::v2::set_value, permission::v2::set_value, get<3>(perm), get<4>(perm));
|
group->permissions()->set_permission(get<0>(perm), {get<1>(perm), get<2>(perm)}, permission::v2::set_value, permission::v2::set_value, get<3>(perm), get<4>(perm));
|
||||||
}
|
}
|
||||||
if(!info->propertyName.empty()) {
|
|
||||||
const auto& prop = property::impl::info<property::InstanceProperties>(info->propertyName);
|
for(const auto& property : info->properties) {
|
||||||
|
const auto& prop = property::impl::info<property::InstanceProperties>(property);
|
||||||
if(*prop == property::SERVERINSTANCE_UNDEFINED) {
|
if(*prop == property::SERVERINSTANCE_UNDEFINED) {
|
||||||
logCritical(LOG_INSTANCE, "Invalid template property name: " + info->propertyName);
|
logCritical(LOG_INSTANCE, "Invalid template property name: " + property);
|
||||||
} else {
|
} else {
|
||||||
this->properties()[prop] = group->groupId();
|
this->properties()[prop] = group->groupId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->save_group_permissions();
|
this->save_group_permissions();
|
||||||
this->getSql()->pool->threads()->wait_for(); //Wait for all permissions to flush
|
this->getSql()->pool->threads()->wait_for(); //Wait for all permissions to flush
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user