commit d0f5564d4e0fe8be8cd9f751b153d3fdae3a498d
parent 10a2fac51b29aa3bf8b8ff1745c24c94c31429eb
Author: Luis Chacón <lechacon@users.noreply.github.com>
Date: Mon, 5 Apr 2021 17:34:31 -0700
Add None to Group Policy values enum (#846)
Diffstat:
5 files changed, 46 insertions(+), 35 deletions(-)
diff --git a/src/AppInstallerCommonCore/GroupPolicy.cpp b/src/AppInstallerCommonCore/GroupPolicy.cpp
@@ -84,9 +84,7 @@ namespace AppInstaller::Settings
}
template <ValuePolicy P>
- void Validate(
- const Registry::Key& policiesKey,
- GroupPolicy::ValuePoliciesMap& policies)
+ void Validate(const Registry::Key& policiesKey, GroupPolicy::ValuePoliciesMap& policies)
{
auto value = details::ValuePolicyMapping<P>::ReadAndValidate(policiesKey);
if (value.has_value())
@@ -95,6 +93,9 @@ namespace AppInstaller::Settings
}
}
+ template <>
+ void Validate<ValuePolicy::None>(const Registry::Key&, GroupPolicy::ValuePoliciesMap&) {};
+
template <size_t... P>
void ValidateAllValuePolicies(
const Registry::Key& policiesKey,
@@ -200,6 +201,11 @@ namespace AppInstaller::Settings
POLICY_MAPPING_DEFAULT_LIST_READ(ValuePolicy::AdditionalSources);
POLICY_MAPPING_DEFAULT_LIST_READ(ValuePolicy::AllowedSources);
+ std::nullopt_t ValuePolicyMapping<ValuePolicy::None>::ReadAndValidate(const Registry::Key&)
+ {
+ return std::nullopt;
+ }
+
std::optional<uint32_t> ValuePolicyMapping<ValuePolicy::SourceAutoUpdateIntervalInMinutes>::ReadAndValidate(const Registry::Key& policiesKey)
{
using Mapping = ValuePolicyMapping<ValuePolicy::SourceAutoUpdateIntervalInMinutes>;
diff --git a/src/AppInstallerCommonCore/Public/winget/ExperimentalFeature.h b/src/AppInstallerCommonCore/Public/winget/ExperimentalFeature.h
@@ -49,10 +49,10 @@ namespace AppInstaller::Settings
ExperimentalFeature& operator=(ExperimentalFeature&&) = default;
static bool IsEnabled(Feature feature);
-
+
#ifndef AICLI_DISABLE_TEST_HOOKS
- static bool IsEnabled(Feature feature, const UserSettings& userSettings);
-#endif
+ static bool IsEnabled(Feature feature, const UserSettings& userSettings);
+#endif
static ExperimentalFeature GetFeature(ExperimentalFeature::Feature feature);
static std::vector<ExperimentalFeature> GetAllFeatures();
diff --git a/src/AppInstallerCommonCore/Public/winget/GroupPolicy.h b/src/AppInstallerCommonCore/Public/winget/GroupPolicy.h
@@ -17,6 +17,7 @@ namespace AppInstaller::Settings
// made up of sub-keys for settings that are lists.
enum class ValuePolicy
{
+ None,
SourceAutoUpdateIntervalInMinutes,
AdditionalSources,
AllowedSources,
@@ -101,11 +102,22 @@ namespace AppInstaller::Settings
// ReadAndValidateItem() - Function that reads a single item from a subkey
};
+ template<>
+ struct ValuePolicyMapping<ValuePolicy::None>
+ {
+ using value_t = std::monostate;
+ using opt_value_t = std::nullopt_t;
+ using opt_ref_value_t = std::nullopt_t;
+ static std::nullopt_t ReadAndValidate(const Registry::Key& policiesKey);
+ };
+
#define POLICY_MAPPING_SPECIALIZATION(_policy_, _type_, _extra_) \
template <> \
struct ValuePolicyMapping<_policy_> \
{ \
using value_t = _type_; \
+ using opt_value_t = std::optional<value_t>; \
+ using opt_ref_value_t = std::optional<std::reference_wrapper<const value_t>>; \
static std::optional<value_t> ReadAndValidate(const Registry::Key& policiesKey); \
_extra_ \
}
@@ -153,7 +165,7 @@ namespace AppInstaller::Settings
// Gets the policy value if it is present
template<ValuePolicy P>
- std::optional<ValueType<P>> GetValue() const
+ typename details::ValuePolicyMapping<P>::opt_value_t GetValue() const
{
if (m_values.Contains(P))
{
@@ -166,7 +178,7 @@ namespace AppInstaller::Settings
}
template<ValuePolicy P>
- std::optional<std::reference_wrapper<const ValueType<P>>> GetValueRef() const
+ typename details::ValuePolicyMapping<P>::opt_ref_value_t GetValueRef() const
{
if (m_values.Contains(P))
{
@@ -178,6 +190,18 @@ namespace AppInstaller::Settings
}
}
+ template<>
+ std::nullopt_t GetValue<ValuePolicy::None>() const
+ {
+ return std::nullopt;
+ }
+
+ template<>
+ std::nullopt_t GetValueRef<ValuePolicy::None>() const
+ {
+ return std::nullopt;
+ }
+
PolicyState GetState(TogglePolicy::Policy policy) const;
// Checks whether a policy is enabled, using an appropriate default when not configured.
diff --git a/src/AppInstallerCommonCore/Public/winget/UserSettings.h b/src/AppInstallerCommonCore/Public/winget/UserSettings.h
@@ -85,7 +85,7 @@ namespace AppInstaller::Settings
// Validate - Function that does semantic validation.
};
-#define SETTINGMAPPING_SPECIALIZATION_EXTEND(_setting_, _json_, _value_, _default_, _path_, _extension_) \
+#define SETTINGMAPPING_SPECIALIZATION_POLICY(_setting_, _json_, _value_, _default_, _path_, _valuePolicy_) \
template <> \
struct SettingMapping<_setting_> \
{ \
@@ -94,18 +94,13 @@ namespace AppInstaller::Settings
static constexpr value_t DefaultValue = _default_; \
static constexpr std::string_view Path = _path_; \
static std::optional<value_t> Validate(const json_t& value); \
- _extension_ \
+ static constexpr ValuePolicy Policy = _valuePolicy_; \
+ using policy_t = GroupPolicy::ValueType<Policy>; \
+ static_assert(Policy == ValuePolicy::None || std::is_same<json_t, policy_t>::value); \
}
#define SETTINGMAPPING_SPECIALIZATION(_setting_, _json_, _value_, _default_, _path_) \
- SETTINGMAPPING_SPECIALIZATION_EXTEND(_setting_, _json_, _value_, _default_, _path_, )
-
-#define SETTINGMAPPING_SPECIALIZATION_POLICY(_setting_, _json_, _value_, _default_, _path_, _valuePolicy_) \
- SETTINGMAPPING_SPECIALIZATION_EXTEND(_setting_, _json_, _value_, _default_, _path_, \
- static constexpr ValuePolicy Policy = _valuePolicy_; \
- using policy_t = GroupPolicy::ValueType<Policy>; \
- static_assert(std::is_same<json_t, policy_t>::value); \
- )
+ SETTINGMAPPING_SPECIALIZATION_POLICY(_setting_, _json_, _value_, _default_, _path_, ValuePolicy::None)
SETTINGMAPPING_SPECIALIZATION(Setting::ProgressBarVisualStyle, std::string, VisualStyle, VisualStyle::Accent, ".visual.progressBar"sv);
SETTINGMAPPING_SPECIALIZATION_POLICY(Setting::AutoUpdateTimeInMinutes, uint32_t, std::chrono::minutes, 5min, ".source.autoUpdateIntervalInMinutes"sv, ValuePolicy::SourceAutoUpdateIntervalInMinutes);
diff --git a/src/AppInstallerCommonCore/UserSettings.cpp b/src/AppInstallerCommonCore/UserSettings.cpp
@@ -65,26 +65,12 @@ namespace AppInstaller::Settings
}
return {};
- }
-
- template <Setting S>
- std::optional<typename details::SettingMapping<S>::policy_t> GetValueFromPolicy(int)
- {
- // return std::nullopt;
- return GroupPolicies().GetValue<details::SettingMapping<S>::Policy>();
- }
-
- template <Setting S>
- std::optional<typename details::SettingMapping<S>::json_t> GetValueFromPolicy(long)
- {
- using T = decltype(std::declval<details::SettingMapping<S>::json_t>());
- return std::nullopt;
- }
+ }
template <Setting S>
std::optional<typename details::SettingMapping<S>::json_t> GetValueFromPolicy()
{
- return GetValueFromPolicy<S>(0);
+ return GroupPolicies().GetValue<details::SettingMapping<S>::Policy>();
}
template <Setting S>
@@ -94,7 +80,7 @@ namespace AppInstaller::Settings
std::vector<UserSettings::Warning>& warnings)
{
// jsoncpp doesn't support std::string_view yet.
- auto path = std::string(details::SettingMapping<S>::Path);
+ auto path = std::string(details::SettingMapping<S>::Path);
// Settings set by Group Policy override anything else. See if there is one.
auto policyValue = GetValueFromPolicy<S>();