This project is read-only.

How to only display "Dashboard" link if user has permissions for it?

Topics: Customizing Orchard, General, Writing modules
Jan 13, 2012 at 4:56 PM

I'm not sure how to check for any kinds of permissions, nor how to do it from a view. I have overriden User.cshtml in my module and in there I want to do a check to only display the Dashboard link if the user has some kind of permissions that should let them enter the dashboard (e.g., editor, admin, super user, etc). 

Right now I just have it checking if the username is "admin", but that obviously won't work for lesser roles who still need to get into the dashboard. 

<span class="user-actions">
            @if (WorkContext.CurrentUser.UserName.Equals("admin", StringComparison.OrdinalIgnoreCase)) {
                @Html.ActionLink(T("Dashboard").ToString(), "Index", new { Area = "Dashboard", Controller = "Admin" })
            @Html.ActionLink(T("Sign Out").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl })

Jan 13, 2012 at 5:09 PM


Jan 13, 2012 at 5:18 PM

Thanks. Is there a simple way to check for permissions to Admin panel, or can I simply check if user is a member of a role like admin or editor? That'd be easier than hunting down all the various Permission's across all modules's namespaces. 

Jan 13, 2012 at 5:25 PM


Jan 13, 2012 at 6:17 PM

This also bugged me so I opened an issue and created a patch :-) (not yet evaluated, though).

Jan 13, 2012 at 7:30 PM
randompete wrote: