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