You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Importing Permissions with Overwrite Option (#3184)
<!-- Thank you for submitting a Pull Request. If you're new to
contributing to BCApps please read our pull request guideline below
* https://github.com/microsoft/BCApps/Contributing.md
-->
#### Summary <!-- Provide a general summary of your changes -->
With this change, I have enabled the user to be able to overwrite
permission sets contained in the import file. Up until now, the
permissions from the import file were merged with the permissions
already present in the permission sets.
The majority of changes were done in this repo but the text for a
confirmation dialog has been changed in the repo containing the Base App
microsoft/BusinessCentralApps#1287
#### Description of the problem
Importing user defined permissions sets leaves permissions in
inconsistent state.
Users tend to test the permissions sets in multiple rounds in a test
system. After they are satisfied with the result they decide to import
it in a production. However the outcome of the import is not reliable.
Users would like to overwrite current user defined permission set with
preserving assignment to the users/security groups. Currently if a
permission set is imported there are two problems:
1. If in a test systems some permissions were reduced to indirect or
removed those changes do not get imported into permissions.
1. If a permission for a certain object is removed in a test system and
then exported and imported to production the permission cannot be
removed.
That means that importing permission sets is basically "additive" and
can only give more "power". There is no easy way to import XX permission
sets that are already assigned to users or security groups and that
those are imported "as is" in the import file.
#### Work Item(s) <!-- Add the issue number here after the #. The issue
needs to be open and approved. Submitting PRs with no linked issues or
unapproved issues is highly discouraged. -->
Fixes#3162
Fixes
[AB#559224](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/559224)
// [SCENARIO] Tenant permission set is exported and imported. Then the same permission set is imported again with changed permissions and should be imported as is without merging.
344
+
345
+
Initialize();
346
+
347
+
NewRoleId := 'Test Permission Set';
348
+
NewName := 'Test Permission Set';
349
+
350
+
// [WHEN] Permission Set C is cloned to get a tenant permission set
351
+
PermissionSetRelation.CopyPermissionSet(NewRoleId, NewName, 'Permission Set C', AppId, Scope::System, Enum::"Permission Set Copy Type"::Clone);
LibraryAssert.IsTrue(TenantPermissionSet.Get(ZeroGuid, NewRoleId), 'Test permission set is missing');
360
+
LibraryAssert.IsTrue(TenantPermission.Get(ZeroGuid, TenantPermissionSet."Role ID", TenantPermission."Object Type"::"Table Data", Database::"Tenant Permission"), 'Included permission to Test permission set is missing');
361
+
362
+
// [WHEN] Existing permission for the permission set is changed
// [WHEN] Import the original tenant permission set that was exported
390
+
TempBlobOriginal.CreateInStream(InStr);
391
+
ImportPermissionSets.SetSource(InStr);
392
+
ImportPermissionSets.SetUpdatePermissions(false);
393
+
ImportPermissionSets.Import();
394
+
395
+
// [THEN] Tenant permission set is found with the correct permissions
396
+
LibraryAssert.IsTrue(TenantPermissionSet.Get(ZeroGuid, NewRoleId), 'Test permission set is missing');
397
+
LibraryAssert.IsTrue(TenantPermission.Get(ZeroGuid, TenantPermissionSet."Role ID", TenantPermission."Object Type"::"Table Data", Database::"Tenant Permission"), 'Included permission to Test permission set is missing');
398
+
LibraryAssert.AreEqual(TenantPermission."Read Permission", TenantPermission."Read Permission"::Yes, 'Read permission is not set correctly.');
399
+
LibraryAssert.AreEqual(TenantPermission."Insert Permission", TenantPermission."Insert Permission"::Indirect, 'Insert permission is not set correctly.');
400
+
LibraryAssert.AreEqual(TenantPermission."Modify Permission", TenantPermission."Modify Permission"::Indirect, 'Modify permission is not set correctly.');
401
+
LibraryAssert.AreEqual(TenantPermission."Delete Permission", TenantPermission."Delete Permission"::" ", 'Delete permission is not set correctly.');
402
+
LibraryAssert.IsFalse(TenantPermission.Get(ZeroGuid, TenantPermissionSet."Role ID", TenantPermission."Object Type"::"Table Data", Database::"Metadata Permission"), 'Metadata permission should not be included');
403
+
404
+
// [WHEN] Import the modified tenant permission set
405
+
TempBlobModified.CreateInStream(InStr);
406
+
Clear(ImportPermissionSets);
407
+
ImportPermissionSets.SetSource(InStr);
408
+
ImportPermissionSets.SetUpdatePermissions(false);
409
+
ImportPermissionSets.Import();
410
+
411
+
// [THEN] Tenant permission set is found with the modified permissions
412
+
LibraryAssert.IsTrue(TenantPermissionSet.Get(ZeroGuid, NewRoleId), 'Test permission set is missing');
413
+
LibraryAssert.IsTrue(TenantPermission.Get(ZeroGuid, TenantPermissionSet."Role ID", TenantPermission."Object Type"::"Table Data", Database::"Tenant Permission"), 'Included permission to Test permission set is missing');
414
+
LibraryAssert.AreEqual(TenantPermission."Read Permission", TenantPermission."Read Permission"::" ", 'Read permission is not set correctly.'); // Import is not additive, the permission should be imported as is
415
+
LibraryAssert.AreEqual(TenantPermission."Insert Permission", TenantPermission."Insert Permission"::Indirect, 'Insert permission is not set correctly.');
416
+
LibraryAssert.AreEqual(TenantPermission."Modify Permission", TenantPermission."Modify Permission"::Indirect, 'Modify permission is not set correctly.');
417
+
LibraryAssert.AreEqual(TenantPermission."Delete Permission", TenantPermission."Delete Permission"::Yes, 'Delete permission is not set correctly.');
418
+
LibraryAssert.IsTrue(TenantPermission.Get(ZeroGuid, TenantPermissionSet."Role ID", TenantPermission."Object Type"::"Table Data", Database::"Metadata Permission"), 'Included permission to Test permission set is missing');
419
+
LibraryAssert.AreEqual(TenantPermission."Read Permission", TenantPermission."Read Permission"::Indirect, 'Read permission is not set correctly.');
420
+
LibraryAssert.AreEqual(TenantPermission."Insert Permission", TenantPermission."Insert Permission"::" ", 'Insert permission is not set correctly.');
421
+
LibraryAssert.AreEqual(TenantPermission."Modify Permission", TenantPermission."Modify Permission"::" ", 'Modify permission is not set correctly.');
422
+
LibraryAssert.AreEqual(TenantPermission."Delete Permission", TenantPermission."Delete Permission"::" ", 'Delete permission is not set correctly.');
0 commit comments