Forums

Forums / Developing Portals / Accessing the current logged in users "permissions" within view

Accessing the current logged in users "permissions" within view

Thread is closed for posting
2 posts, 1 answered
  1. David Woof
    David  Woof avatar
    4 posts
    Registered:
    11 Sep 2018
    05 Jun 2019
    Link to this post
    Hey,

    I need to know the current logged in users permissions with a mvc razor view. 

    I've created my own template for a ListView and I need to display a piece of data solely based on the users permissions. 

    now within the form/page I would normally set the "permissions" there, but this must be done as apart of the logic of the view.

    Is this something that's possible/if so where on the TpcListViewViewModel does the relevant information exist? 

    Thanks
  2. Josh
    Josh avatar
    47 posts
    Registered:
    01 Jun 2018
    Answered
    30 Oct 2019 in reply to David Woof
    Link to this post

    Hello David,

    Using out-of-the-box functionality there is no standard way to access a User’s permissions to hide or show content within a TPC template. Although there are two different approaches that you could use to solve this issue. The simpler approach is to set permissions on the TPC ListView widget so that it only displays for Users with or without certain permissions. The more complex approach would be to create your own custom Sitefinity Page or Widget using ASP.NET MVC where you can specify the page model yourself and thereby pass the permissions of the user to the model referenced by the View in the Controller.

    #1 Setting Widget Permissions

    All Sitefinity Widgets (including TPC Widgets) can specify the permissions required for the widget to render. To specify the permissions, you click the dropdown on the widget designer that says More ▼, and then in the dropdown menu select Permissions.

    {Target Widget Designer} -> More -> Permissions

    Once you have entered the Permissions screen you will be able to specify the permissions required for all the actions of the Widget including View, Move, Edit, Delete, Change, and Change Permissions. For your requirement, you would allow only the user with the specified permissions to view the TPC ListView.

    More information on Sitefinity Permissions can be found here: https://www.progress.com/documentation/sitefinity-cms/overview-permissions

    #2 Create Custom Sitefinity Page or Widget using ASP.NET MVC

    This approach requires more development knowledge and tools, although can be used to meet more complex requirements. Below is an excerpt from the Sitefinity website regarding custom development using ASP.NET MVC and Sitefinity.

    “With Sitefinity CMS, you can leverage the classic, pure, and hybrid modes of MVC. The mode you use depends on your development process as well as the functionality you want to implement. The classic mode, as the name suggests, is the mode in which a page is represented by one controller (in essence, bypassing Sitefinity CMS page routes) – as it is outside of the context of Sitefinity CMS. The pure and hybrid modes are Sitefinity-specific and bring ASP.NET MVC with a Sitefinity CMS implementation. Namely, controllers are interpreted as widgets, so you can build Sitefinity CMS widgets from controllers and have more than one controller within a page” (Sitefinity).

    Using this approach, you have the freedom to pass nearly anything from the Controller to your custom Pages or Widgets, including the permissions of the currently logged in user. Though we would certainly recommend using the built-in Permissions functionality of Sitefinity where possible.

    More information on Developing for Sitefinity using ASP.NET MVC can be found here: https://www.progress.com/documentation/sitefinity-cms/for-developers-develop-with-sitefinity-and-asp-net-mvc

    Hopefully, this information proves useful. Please let us know if you have any other issues by replying to this thread, or reach out to support@crmportalconnector.com if you need further assistance.

    Cheers,

    Josh

2 posts, 1 answered