Merge branch 'master' into 1.4.0

This commit is contained in:
WolverinDEV 2019-09-22 14:09:42 +02:00
commit 7822d20efe
2 changed files with 23 additions and 17 deletions

View File

@ -238,7 +238,7 @@ inline sql::result load_permissions_v2(const std::shared_ptr<TSServer>& server,
auto server_id = server ? server->getServerId() : 0; auto server_id = server ? server->getServerId() : 0;
return command.query([&](int length, char** values, char** names){ return command.query([&](int length, char** values, char** names){
permission::PermissionType key = permission::PermissionType::undefined; permission::PermissionType key = permission::PermissionType::undefined;
permission::PermissionValue value = 0, granted = 0; permission::PermissionValue value = permNotGranted, granted = permNotGranted;
bool negated = false, skipped = false; bool negated = false, skipped = false;
std::shared_ptr<BasicChannel> channel; std::shared_ptr<BasicChannel> channel;
@ -342,9 +342,9 @@ std::shared_ptr<v2::PermissionManager> DatabaseHelper::loadClientPermissionManag
auto channel = perm->channelId > 0 ? server->getChannelTree()->findChannel(perm->channelId) : nullptr; auto channel = perm->channelId > 0 ? server->getChannelTree()->findChannel(perm->channelId) : nullptr;
if(channel) if(channel)
pMgr->load_permission(perm->permission->type, {perm->value, perm->grant}, channel->channelId(), perm->flag_negate, perm->flag_skip, perm->value != permNotGranted, perm->grant != permNotGranted); pMgr->load_permission(perm->permission->type, {perm->value, perm->grant}, channel->channelId(), perm->flag_skip, perm->flag_negate, perm->value != permNotGranted, perm->grant != permNotGranted);
else else
pMgr->load_permission(perm->permission->type, {perm->value, perm->grant}, perm->flag_negate, perm->flag_skip, perm->value != permNotGranted, perm->grant != permNotGranted); pMgr->load_permission(perm->permission->type, {perm->value, perm->grant}, perm->flag_skip, perm->flag_negate, perm->value != permNotGranted, perm->grant != permNotGranted);
} }
} }
loaded = true; loaded = true;
@ -384,6 +384,8 @@ void DatabaseHelper::saveClientPermissions(const std::shared_ptr<ts::server::TSS
std::string query = update.flag_delete ? DELETE_COMMAND : (update.flag_db ? UPDATE_COMMAND : INSERT_COMMAND); std::string query = update.flag_delete ? DELETE_COMMAND : (update.flag_db ? UPDATE_COMMAND : INSERT_COMMAND);
auto permission_data = permission::resolvePermissionData(update.permission); auto permission_data = permission::resolvePermissionData(update.permission);
auto value = update.update_value == v2::delete_value ? permNotGranted : update.values.value;
auto grant = update.update_grant == v2::delete_value ? permNotGranted : update.values.grant;
logTrace(server_id, "[CHANNEL] Updating client permission for client {}: {}. New value: {}. New grant: {}. Query: {}", logTrace(server_id, "[CHANNEL] Updating client permission for client {}: {}. New value: {}. New grant: {}. Query: {}",
client_dbid, client_dbid,
permission_data->name, permission_data->name,
@ -398,8 +400,8 @@ void DatabaseHelper::saveClientPermissions(const std::shared_ptr<ts::server::TSS
variable{":type", permission::SQL_PERM_USER}, variable{":type", permission::SQL_PERM_USER},
variable{":permId", permission_data->name}, variable{":permId", permission_data->name},
variable{":value", update.values.value}, variable{":value", value},
variable{":grant", update.values.grant}, variable{":grant", grant},
variable{":flag_skip", update.flag_skip}, variable{":flag_skip", update.flag_skip},
variable{":flag_negate", update.flag_negate}) variable{":flag_negate", update.flag_negate})
.executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "future error"}); .executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "future error"});
@ -423,7 +425,7 @@ std::shared_ptr<permission::v2::PermissionManager> DatabaseHelper::loadGroupPerm
if(entry) { if(entry) {
for(const auto& perm : entry->permissions) { for(const auto& perm : entry->permissions) {
if(perm->type == permission::SQL_PERM_GROUP && perm->id == group_id) { if(perm->type == permission::SQL_PERM_GROUP && perm->id == group_id) {
result->load_permission(perm->permission->type, {perm->value, perm->grant}, perm->flag_negate, perm->flag_skip, perm->value != permNotGranted, perm->grant != permNotGranted); result->load_permission(perm->permission->type, {perm->value, perm->grant}, perm->flag_skip, perm->flag_negate, perm->value != permNotGranted, perm->grant != permNotGranted);
} }
} }
return result; return result;
@ -449,11 +451,13 @@ void DatabaseHelper::saveGroupPermissions(const std::shared_ptr<ts::server::TSSe
std::string query = update.flag_delete ? DELETE_COMMAND : (update.flag_db ? UPDATE_COMMAND : INSERT_COMMAND); std::string query = update.flag_delete ? DELETE_COMMAND : (update.flag_db ? UPDATE_COMMAND : INSERT_COMMAND);
auto permission_data = permission::resolvePermissionData(update.permission); auto permission_data = permission::resolvePermissionData(update.permission);
auto value = update.update_value == v2::delete_value ? permNotGranted : update.values.value;
auto grant = update.update_grant == v2::delete_value ? permNotGranted : update.values.grant;
logTrace(server_id, "[CHANNEL] Updating group permission for group {}: {}. New value: {}. New grant: {}. Query: {}", logTrace(server_id, "[CHANNEL] Updating group permission for group {}: {}. New value: {}. New grant: {}. Query: {}",
group_id, group_id,
permission_data->name, permission_data->name,
update.values.value, value,
update.values.grant, grant,
query query
); );
sql::command(this->sql, query, sql::command(this->sql, query,
@ -463,8 +467,8 @@ void DatabaseHelper::saveGroupPermissions(const std::shared_ptr<ts::server::TSSe
variable{":type", permission::SQL_PERM_GROUP}, variable{":type", permission::SQL_PERM_GROUP},
variable{":permId", permission_data->name}, variable{":permId", permission_data->name},
variable{":value", update.values.value}, variable{":value", value},
variable{":grant", update.values.grant}, variable{":grant", grant},
variable{":flag_skip", update.flag_skip}, variable{":flag_skip", update.flag_skip},
variable{":flag_negate", update.flag_negate}) variable{":flag_negate", update.flag_negate})
.executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "future error"}); .executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "future error"});
@ -568,7 +572,7 @@ std::shared_ptr<permission::v2::PermissionManager> DatabaseHelper::loadChannelPe
if(entry) { if(entry) {
for(const auto& perm : entry->permissions) { for(const auto& perm : entry->permissions) {
if(perm->type == permission::SQL_PERM_CHANNEL && perm->channelId == channel) { if(perm->type == permission::SQL_PERM_CHANNEL && perm->channelId == channel) {
result->load_permission(perm->permission->type, {perm->value, perm->grant}, perm->flag_negate, perm->flag_skip, perm->value != permNotGranted, perm->grant != permNotGranted); result->load_permission(perm->permission->type, {perm->value, perm->grant}, perm->flag_skip, perm->flag_negate, perm->value != permNotGranted, perm->grant != permNotGranted);
} }
} }
return result; return result;
@ -593,12 +597,14 @@ void DatabaseHelper::saveChannelPermissions(const std::shared_ptr<ts::server::TS
for(auto& update : updates) { for(auto& update : updates) {
std::string query = update.flag_delete ? DELETE_COMMAND : (update.flag_db ? UPDATE_COMMAND : INSERT_COMMAND); std::string query = update.flag_delete ? DELETE_COMMAND : (update.flag_db ? UPDATE_COMMAND : INSERT_COMMAND);
auto value = update.update_value == v2::delete_value ? permNotGranted : update.values.value;
auto grant = update.update_grant == v2::delete_value ? permNotGranted : update.values.grant;
auto permission_data = permission::resolvePermissionData(update.permission); auto permission_data = permission::resolvePermissionData(update.permission);
logTrace(server_id, "[CHANNEL] Updating channel permission for channel {}: {}. New value: {}. New grant: {}. Query: {}", logTrace(server_id, "[CHANNEL] Updating channel permission for channel {}: {}. New value: {}. New grant: {}. Query: {}",
channel_id, channel_id,
permission_data->name, permission_data->name,
update.values.value, value,
update.values.grant, grant,
query query
); );
sql::command(this->sql, query, sql::command(this->sql, query,
@ -608,8 +614,8 @@ void DatabaseHelper::saveChannelPermissions(const std::shared_ptr<ts::server::TS
variable{":type", permission::SQL_PERM_CHANNEL}, variable{":type", permission::SQL_PERM_CHANNEL},
variable{":permId", permission_data->name}, variable{":permId", permission_data->name},
variable{":value", update.values.value}, variable{":value", value},
variable{":grant", update.values.grant}, variable{":grant", grant},
variable{":flag_skip", update.flag_skip}, variable{":flag_skip", update.flag_skip},
variable{":flag_negate", update.flag_negate}) variable{":flag_negate", update.flag_negate})
.executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "future error"}); .executeLater().waitAndGetLater(LOG_SQL_CMD, {-1, "future error"});
@ -1100,7 +1106,7 @@ void DatabaseHelper::loadStartupPermissionCache() {
StartupPermissionArgument arg; StartupPermissionArgument arg;
sql::command(this->sql, "SELECT `serverId`, `type`, `id`, `channelId`, `permId`, `value`, `grant`, `flag_skip`, `flag_negate` FROM permissions ORDER BY `serverId`").query([&](StartupPermissionArgument* arg, int length, char** values, char** names) { sql::command(this->sql, "SELECT `serverId`, `type`, `id`, `channelId`, `permId`, `value`, `grant`, `flag_skip`, `flag_negate` FROM permissions ORDER BY `serverId`").query([&](StartupPermissionArgument* arg, int length, char** values, char** names) {
auto key = permission::PermissionTypeEntry::unknown; auto key = permission::PermissionTypeEntry::unknown;
permission::PermissionValue value = 0, granted = 0; permission::PermissionValue value = permNotGranted, granted = permNotGranted;
permission::PermissionSqlType type = SQL_PERM_GROUP; permission::PermissionSqlType type = SQL_PERM_GROUP;
bool negated = false, skipped = false; bool negated = false, skipped = false;
ChannelId channel = 0; ChannelId channel = 0;

2
shared

@ -1 +1 @@
Subproject commit 837852114f92d0f3acb94b5e0807dee265bf40e5 Subproject commit cb73d9df3258eaf59e4799c9e54d5f865e891734