From fd2367d483babeb74162406b4dd9d5de26e144df Mon Sep 17 00:00:00 2001 From: "Wei (Waley) Zhang" Date: Tue, 2 Feb 2021 08:31:44 -0800 Subject: [PATCH 1/6] Fixed a graphing calculator "permissions" bug caused by PR #1426 (#1471) ## Fixes a bug caused by https://github.com/microsoft/calculator/pull/1426#. ### Description of the changes: - The PR #1426 can cause a crash when no users are returned via `User::FindAllAsync(UserType::LocalUser)` when subsequently trying to access the first user. The existing code also does not guarantee that the returned user is the currently active user. - This fix retrieves the user that opened the app and passes this user into a function to check if this user has the proper permissions to access the graphing mode. This makes sense since the active user is indistinguishable (at least from the app's perspective) to the user who opened the app. This user's permissions are then propagated downwards to properly set up the navigation menu of the app. - Implementation detail worth pointing out: `s_categoryManifest` is what is used to populate the navigation menu of the app, but this variable is static by design, so a separate function was written to override the appropriate `isEnabled` value in `s_categoryManifest`. This function is called by `onLaunched`. ### How changes were validated: - Manual testing --- src/CalcViewModel/Common/NavCategory.cpp | 37 +++++++++++++++++++----- src/CalcViewModel/Common/NavCategory.h | 4 ++- src/Calculator/App.xaml.cpp | 2 +- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/CalcViewModel/Common/NavCategory.cpp b/src/CalcViewModel/Common/NavCategory.cpp index 6af89959..3f4c2158 100644 --- a/src/CalcViewModel/Common/NavCategory.cpp +++ b/src/CalcViewModel/Common/NavCategory.cpp @@ -60,7 +60,7 @@ bool IsGraphingModeAvailable() } Box ^ _isGraphingModeEnabledCached = nullptr; -bool IsGraphingModeEnabled() +bool IsGraphingModeEnabled(User ^ currentUser = nullptr) { if (!IsGraphingModeAvailable()) { @@ -72,17 +72,19 @@ bool IsGraphingModeEnabled() return _isGraphingModeEnabledCached->Value; } - User ^ firstUser; - create_task(User::FindAllAsync(UserType::LocalUser)).then([&firstUser](IVectorView ^ users) { - firstUser = users->GetAt(0); }).wait(); - auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser(firstUser, L"Education", L"AllowGraphingCalculator"); - _isGraphingModeEnabledCached = namedPolicyData->GetBoolean() == true; + if (!currentUser) + { + return true; + } + + auto namedPolicyData = NamedPolicy::GetPolicyFromPathForUser(currentUser, L"Education", L"AllowGraphingCalculator"); + _isGraphingModeEnabledCached = namedPolicyData->GetBoolean() == true; return _isGraphingModeEnabledCached->Value; } // The order of items in this list determines the order of items in the menu. -static const list s_categoryManifest = [] { +static list s_categoryManifest = [] { auto res = list{ NavCategoryInitializer{ ViewMode::Standard, STANDARD_ID, L"Standard", @@ -108,7 +110,7 @@ static const list s_categoryManifest = [] { bool supportGraphingCalculator = IsGraphingModeAvailable(); if (supportGraphingCalculator) { - const bool isEnabled = IsGraphingModeEnabled(); + bool isEnabled = IsGraphingModeEnabled(); res.push_back(NavCategoryInitializer{ ViewMode::Graphing, GRAPHING_ID, L"Graphing", @@ -276,6 +278,25 @@ static const list s_categoryManifest = [] { return res; }(); +void NavCategory::InitializeCategoryManifest(User ^ user) +{ + int i = 0; + for (NavCategoryInitializer category : s_categoryManifest) + { + if (category.viewMode == ViewMode::Graphing) + { + auto navCatInit = s_categoryManifest.begin(); + std::advance(navCatInit, i); + (*navCatInit).isEnabled = IsGraphingModeEnabled(user); + break; + } + else + { + i++; + } + } + } + // This function should only be used when storing the mode to app data. int NavCategory::Serialize(ViewMode mode) { diff --git a/src/CalcViewModel/Common/NavCategory.h b/src/CalcViewModel/Common/NavCategory.h index b7c46057..c0ce95f0 100644 --- a/src/CalcViewModel/Common/NavCategory.h +++ b/src/CalcViewModel/Common/NavCategory.h @@ -92,7 +92,7 @@ namespace CalculatorApp const MyVirtualKey virtualKey; const wchar_t* const accessKey; const bool supportsNegative; - const bool isEnabled; + bool isEnabled; }; private @@ -140,6 +140,8 @@ namespace CalculatorApp static bool IsDateCalculatorViewMode(ViewMode mode); static bool IsConverterViewMode(ViewMode mode); + static void InitializeCategoryManifest(Windows::System::User ^ user); + static Platform::String ^ GetFriendlyName(ViewMode mode); static Platform::String ^ GetNameResourceKey(ViewMode mode); static CategoryGroupType GetGroupType(ViewMode mode); diff --git a/src/Calculator/App.xaml.cpp b/src/Calculator/App.xaml.cpp index b8f7702d..39f8e7fc 100644 --- a/src/Calculator/App.xaml.cpp +++ b/src/Calculator/App.xaml.cpp @@ -198,12 +198,12 @@ void App::OnLaunched(LaunchActivatedEventArgs ^ args) // If the app got pre-launch activated, then save that state in a flag m_preLaunched = true; } + NavCategory::InitializeCategoryManifest(args->User); OnAppLaunch(args, args->Arguments); } void App::OnAppLaunch(IActivatedEventArgs ^ args, String ^ argument) { - // Uncomment the following lines to display frame-rate and per-frame CPU usage info. //#if _DEBUG // if (IsDebuggerPresent()) From ef00b916196f64ee398ce8b357c389cc7a6043bc Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Tue, 2 Feb 2021 11:05:26 -0800 Subject: [PATCH 2/6] Update nuget.config file (#1486) --- src/nuget.config | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/nuget.config b/src/nuget.config index 63a9d4e6..2b0a8e9e 100644 --- a/src/nuget.config +++ b/src/nuget.config @@ -1,13 +1,11 @@ - - - - + + - - - - + + + + \ No newline at end of file From 436eb1718dc01b57bd7b6207201f18ce4f3fb202 Mon Sep 17 00:00:00 2001 From: Cory Volk <57420088+volkcor@users.noreply.github.com> Date: Tue, 2 Feb 2021 11:40:57 -0800 Subject: [PATCH 3/6] Update2102release (#1484) --- build/pipelines/azure-pipelines.release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build/pipelines/azure-pipelines.release.yaml b/build/pipelines/azure-pipelines.release.yaml index a53ab1db..295be1ee 100644 --- a/build/pipelines/azure-pipelines.release.yaml +++ b/build/pipelines/azure-pipelines.release.yaml @@ -16,8 +16,8 @@ pr: none variables: versionMajor: 10 - versionMinor: 2101 - versionBuild: $[counter('10.2101.*', 0)] + versionMinor: 2102 + versionBuild: $[counter('10.2102.*', 0)] versionPatch: 0 name: '$(versionMajor).$(versionMinor).$(versionBuild).$(versionPatch)' From 24b1aca64048341d6c0a371aa16a137c85c3e49f Mon Sep 17 00:00:00 2001 From: KermanX <63178754+KermanX@users.noreply.github.com> Date: Wed, 3 Feb 2021 03:42:45 +0800 Subject: [PATCH 4/6] Update ManualTests.md (#1485) --- docs/ManualTests.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ManualTests.md b/docs/ManualTests.md index 884f0aef..a0f3094f 100644 --- a/docs/ManualTests.md +++ b/docs/ManualTests.md @@ -10,7 +10,7 @@ These manual tests are run before every release of the Calculator app. **Test 1** Steps: 1. From the Standard Calculator page, input “3”, “+”, “3”, “Enter” on the keyboard -Expected: “6” shows up in the display +*Expected: “6” shows up in the display * 2. Input “4”, “-”, “2”, “=” using the in-app buttons *Expected: “2” shows up in the display* From fdf7242cf069037f149c4f1753531b12aa417275 Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Wed, 3 Feb 2021 07:32:38 -0800 Subject: [PATCH 5/6] Update build year to 2021 (#1487) --- src/Calculator/AboutFlyout.xaml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Calculator/AboutFlyout.xaml.cpp b/src/Calculator/AboutFlyout.xaml.cpp index 9a84a752..c89c7df5 100644 --- a/src/Calculator/AboutFlyout.xaml.cpp +++ b/src/Calculator/AboutFlyout.xaml.cpp @@ -21,7 +21,7 @@ using namespace Windows::UI::Xaml::Controls::Primitives; using namespace Windows::UI::Xaml::Data; #ifndef BUILD_YEAR -#define BUILD_YEAR 2020 +#define BUILD_YEAR 2021 #endif AboutFlyout::AboutFlyout() From 6a34a31ec6c072fb593c877ae81a070739f44a2f Mon Sep 17 00:00:00 2001 From: Matt Cooley Date: Fri, 5 Feb 2021 11:40:27 -0800 Subject: [PATCH 6/6] Update internal loc pipeline account (#1488) --- build/pipelines/azure-pipelines.loc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pipelines/azure-pipelines.loc.yaml b/build/pipelines/azure-pipelines.loc.yaml index a90e401c..cf02b223 100644 --- a/build/pipelines/azure-pipelines.loc.yaml +++ b/build/pipelines/azure-pipelines.loc.yaml @@ -30,7 +30,7 @@ jobs: displayName: Send resources to Touchdown Build inputs: teamId: 86 - authId: d3dd8113-65b3-4526-bdca-a00a7d1c37ba + authId: bf6d44ca-3210-4cfa-833f-c79f164ea27b authKey: $(LocServiceKey) isPreview: false relativePathRoot: src/Calculator/Resources/en-US/