diff --git a/src/main.cpp b/src/main.cpp index e8a3713..52ffb22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -106,9 +106,9 @@ namespace auto check_operation_for_violations(const std::string& _object_name, ruleExecInfo_t& rei) -> irods::error { const auto config = load_plugin_config(rei); - if(config == std::nullopt) { + if (config == std::nullopt) { return CODE(RULE_ENGINE_CONTINUE); - } + } const auto prefixes_iter = config->find("prefixes"); if (prefixes_iter == config->cend()) { return CODE(RULE_ENGINE_CONTINUE); @@ -121,10 +121,7 @@ namespace return CODE(RULE_ENGINE_CONTINUE); } const auto admin_iter = config->find("admin_only"); - if (admin_iter == config->cend()) { - return CODE(RULE_ENGINE_CONTINUE); - } - if (admin_iter->get()) { + if (admin_iter != config->cend() && admin_iter->get()) { return user_is_administrator(*rei.rsComm); } @@ -149,7 +146,8 @@ namespace return ERROR(CAT_INSUFFICIENT_PRIVILEGE_LEVEL, "User is not allowed to modify metadata"); } - auto handle_pep_api_mod_avu_metadata_pre(std::list& _rule_arguments, irods::callback _effect_handler) -> irods::error + auto handle_pep_api_mod_avu_metadata_pre(std::list& _rule_arguments, irods::callback _effect_handler) + -> irods::error { try { auto* input = boost::any_cast(*std::next(std::begin(_rule_arguments), 2)); @@ -218,8 +216,8 @@ namespace return CODE(RULE_ENGINE_CONTINUE); } - auto handle_pep_api_atomic_apply_metadata_operations_pre(std::list& _rule_arguments, irods::callback _effect_handler) - -> irods::error + auto handle_pep_api_atomic_apply_metadata_operations_pre(std::list& _rule_arguments, + irods::callback _effect_handler) -> irods::error { auto is_input_valid = [](const bytesBuf_t* _input) -> std::tuple { if (!_input) { @@ -251,7 +249,8 @@ namespace auto& rei = get_rei(_effect_handler); for (auto&& op : operations) { - const auto err_code = check_operation_for_violations(op.at("attribute").get_ref(), rei); + const auto err_code = + check_operation_for_violations(op.at("attribute").get_ref(), rei); if (!err_code.ok()) { return err_code; } @@ -260,7 +259,9 @@ namespace return CODE(RULE_ENGINE_CONTINUE); } catch (const json::exception& e) { - log_re::error({{"log_message", "Failed to parse input into JSON"}, {"error_message", e.what()}, {"rule_engine_plugin", "metadata_guard"}}); + log_re::error({{"log_message", "Failed to parse input into JSON"}, + {"error_message", e.what()}, + {"rule_engine_plugin", "metadata_guard"}}); } catch (const std::exception& e) { log_re::error({{"log_message", e.what()}, {"rule_engine_plugin", "metadata_guard"}}); @@ -275,8 +276,9 @@ namespace { static const std::unordered_map&, irods::callback)>> - lookup_table{{"pep_api_mod_avu_metadata_pre", handle_pep_api_mod_avu_metadata_pre}, - {"pep_api_atomic_apply_metadata_operations_pre", handle_pep_api_atomic_apply_metadata_operations_pre}}; + lookup_table{ + {"pep_api_mod_avu_metadata_pre", handle_pep_api_mod_avu_metadata_pre}, + {"pep_api_atomic_apply_metadata_operations_pre", handle_pep_api_atomic_apply_metadata_operations_pre}}; static const auto rule_iterator = lookup_table.find(_rule_name);