Skip to content
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

Add permission support for menu items #17263

Merged
merged 18 commits into from
Jan 8, 2025
Merged

Conversation

MikeAlhayek
Copy link
Member

Fix #12748

{
ArgumentException.ThrowIfNullOrEmpty(name);

if (_permissions is null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the dictionary if it's initialized, and just iterating the providers if not? This way the first match will return the permission.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we don't load the list first, that will cause enumeration for each name lookup which will defeat the purpose.

return _permissions.Values;
}

private async Task LoadPermissionsAsync()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure there is a reason to create this. GetPermissionsAsync could do the same directly. Even if you don't need the result.

Copy link
Member Author

@MikeAlhayek MikeAlhayek Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually did you how you described it. But I find it more readable this way.

return null;
}

public async ValueTask<IEnumerable<Permission>> GetPermissionsAsync()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you return IReadOnlyList<Permission> all the ToArray() can be removed. And the result can be arrays or lists. Same for ByNames.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .ToArray() are needed convert IEnumerable to IList I don't think there is a benefit on using IReadOnlyList unless I am missed something. I did some cleanup now to use the FindByNamesAsync extension in more places.

@MikeAlhayek MikeAlhayek merged commit abbd3e8 into main Jan 8, 2025
13 checks passed
@MikeAlhayek MikeAlhayek deleted the ma/admin-menu-permission branch January 8, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add optional permission check for menu items when adding new menu items
2 participants