-
Notifications
You must be signed in to change notification settings - Fork 0
Add type-safe execute privilege helpers for Custom APIs #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6790085
Add type-safe execute privilege helpers for Custom APIs
mkholt b866365
Add type-safe execute privilege helpers for Custom APIs
mkholt 8dd4ad4
Merge branch 'execute-privilege-name-helper-bf0' of https://github.co…
mkholt 7d62412
Clarify execute-privilege XML docs
mkholt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| namespace XrmPluginCore.Enums | ||
| { | ||
| /// <summary> | ||
| /// Standard Dataverse table (entity) privileges.<br/> | ||
|
mkholt marked this conversation as resolved.
|
||
| /// Each value maps to a privilege whose name follows the convention | ||
|
mkholt marked this conversation as resolved.
|
||
| /// <c>prv{Privilege}{EntityLogicalName}</c>, e.g. <see cref="Read"/> on the | ||
| /// <c>account</c> table resolves to <c>prvReadaccount</c>. | ||
| /// </summary> | ||
| public enum Privilege | ||
| { | ||
| /// <summary> | ||
| /// Permission to create a record (<c>prvCreate...</c>). | ||
| /// </summary> | ||
| Create = 0, | ||
|
|
||
| /// <summary> | ||
| /// Permission to read a record (<c>prvRead...</c>). | ||
| /// </summary> | ||
| Read = 1, | ||
|
|
||
| /// <summary> | ||
| /// Permission to update a record (<c>prvWrite...</c>). This is the "Update" of CRUD; | ||
| /// Dataverse names the update privilege "Write". | ||
| /// </summary> | ||
| Write = 2, | ||
|
|
||
| /// <summary> | ||
| /// Permission to delete a record (<c>prvDelete...</c>). | ||
| /// </summary> | ||
| Delete = 3, | ||
|
|
||
| /// <summary> | ||
| /// Permission to associate a record with this table from another record (<c>prvAppend...</c>). | ||
| /// </summary> | ||
| Append = 4, | ||
|
|
||
| /// <summary> | ||
| /// Permission to associate another record with a record of this table (<c>prvAppendTo...</c>). | ||
| /// </summary> | ||
| AppendTo = 5, | ||
|
|
||
| /// <summary> | ||
| /// Permission to assign a record to another user (<c>prvAssign...</c>). | ||
| /// </summary> | ||
| Assign = 6, | ||
|
|
||
| /// <summary> | ||
| /// Permission to share a record with another user or team (<c>prvShare...</c>). | ||
| /// </summary> | ||
| Share = 7, | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| using System; | ||
| using XrmPluginCore.Enums; | ||
|
|
||
| namespace XrmPluginCore.Helpers; | ||
|
|
||
| internal static class PrivilegeNameResolver | ||
| { | ||
| /// <summary> | ||
| /// Builds the Dataverse execute-privilege name for the given <paramref name="privilege"/> on the | ||
| /// supplied entity, following the <c>prv{Privilege}{EntityLogicalName}</c> convention. | ||
| /// For example, <see cref="Privilege.Read"/> on <c>account</c> resolves to <c>prvReadaccount</c>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Privilege names predate the schema name concept and are based on the entity logical name | ||
| /// (e.g. <c>account</c>), so the logical name is used verbatim. | ||
| /// </remarks> | ||
| public static string GetExecutePrivilegeName(Privilege privilege, string entityLogicalName) | ||
| { | ||
| return $"prv{GetPrivilegeVerb(privilege)}{entityLogicalName}"; | ||
| } | ||
|
mkholt marked this conversation as resolved.
|
||
|
|
||
| private static string GetPrivilegeVerb(Privilege privilege) | ||
| { | ||
| switch (privilege) | ||
| { | ||
| case Privilege.Create: return "Create"; | ||
| case Privilege.Read: return "Read"; | ||
| case Privilege.Write: return "Write"; | ||
| case Privilege.Delete: return "Delete"; | ||
| case Privilege.Append: return "Append"; | ||
| case Privilege.AppendTo: return "AppendTo"; | ||
| case Privilege.Assign: return "Assign"; | ||
| case Privilege.Share: return "Share"; | ||
| default: | ||
| throw new ArgumentOutOfRangeException(nameof(privilege), privilege, "Unknown privilege."); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.