Custom content and permissions check

Former Member
Former Member

Hi

I created a custom application and content.

In my ApplicationType class I extended IPermissionRegistrar

and register permissions:

public void RegisterPermissions(IPermissionRegistrarController permissionController) {
            PermissionConfiguration allowPermissionConfiguration = RoadTestService.GetDefaultAllowPermissionConfiguration();
            PermissionConfiguration disallowPermissionConfiguration = new PermissionConfiguration {
                Joinless = new JoinlessGroupPermissionConfiguration {
                    Administrators = true,
                    Owners = true,
                    Moderators = false,
                    RegisteredUsers = false,
                    Everyone = false
                },
                PublicOpen = new MembershipGroupPermissionConfiguration {
                    Owners = true,
                    Managers = false,
                    Members = false,
                    RegisteredUsers = false,
                    Everyone = false
                },
                PublicClosed = new MembershipGroupPermissionConfiguration {
                    Owners = true,
                    Managers = false,
                    Members = false,
                    RegisteredUsers = false,
                    Everyone = false
                },
                PrivateListed = new MembershipGroupPermissionConfiguration {
                    Owners = true,
                    Managers = false,
                    Members = false
                },
                PrivateUnlisted = new MembershipGroupPermissionConfiguration {
                    Owners = true,
                    Managers = false,
                    Members = false
                }
            };

            permissionController.Register(new RoadTestPermission(RoadTestConstants.PermissionItemCreate, "Create RoadTest", "Enables users to create RoadTest.",
                RoadTestConstants.RoadTestItemApplicationTypeId, disallowPermissionConfiguration));

...
        }

On Permissions settings for group I set this permission for all roles

and also added my custom app to this group.

Then I try to check this permission (from admin user, who is also owner of the group):

Apis.Get<IPermissions>().CheckPermission(RoadTestConstants.PermissionItemCreate, userId, 
new PermissionCheckOptions {ApplicationTypeId = RoadTestConstants.RoadTestItemApplicationTypeId,ApplicationId = applicationId,ContentTypeId = Guid.Empty,ContentId = Guid.Empty});

I almost recive error: The content is not secured.


Then I tryed to extend my ApplicationType class with ISecuredContentType (like it done in WikiApplicationType)
public partial class RoadTestItemApplicationType : ISecuredContentType {
        public Guid GetSecurableId(IContent content) {
            return content.ContentId;
        }

        public Guid GetContentPermissionId(IContent content) {
            return ContentTypeId;
        }

        public Guid DefaultPermissionId => ContentTypeId;
        public Guid DefaultContentPermissionId => RoadTestConstants.PermissionApplicationItemView;
    }

and now I recive PermissionCheck with IsAllowed=false;


Does someone have working example or manual how to work with permissions on Telligent?



  • Former Member
    0 Former Member in reply to Patrick M.

    Thank you for links. I read them both and also found answer with ISecuredContentType for my custom content type

    IContent ISecuredContentType.Get(Guid contentId) {
        return _roadTestReviewApplicationService.GetApplication(contentId);
    }
    
    public Guid GetSecurableId(IContent content) {
        return content.ContentId;
    }
    
    public Guid GetContentPermissionId(IContent content) {
        return ContentTypeId;
    }
    
    public Guid DefaultPermissionId => ContentTypeId;
    public Guid DefaultContentPermissionId => RoadTestConstants.PermissionApplicationReviewView;

    and
    _permissionRegistrarController.RegisterSecurableApplication(applicationId, RoadTestConstants.RoadTestItemApplicationTypeId, containerId);



    But now I have a lot of exceptions in logs like:

    UnknownException: An error occurred while registering a content type for bookmarking: 
    'RoadTests.Plugins.RoadTestReviewContentType'. (An error occurred while initializing plugins. 
    Details of the issue were logged for review by the administrator.) ---> 
    System.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_te_Content_ContentPermissions_cs_Security_Permissions". 
    The conflict occurred in database "TelligentCommunity11", table "dbo.cs_Security_Permissions", column 'PermissionId'.
    The statement has been terminated.
    ...
    at Telligent.Evolution.Data.ContentSqlDataProvider.RegisterContentPermissions(Guid contentPermissionId, Guid serviceType, Guid permissionType, Guid permissionId)
    at Telligent.Evolution.Api.Content.ContentService.RegisterContentPermissions(Guid contentPermissionId, Guid serviceType, Guid permissionType, Guid permissionId)
    at Telligent.Evolution.CoreServices.Bookmarks.Implementations.BookmarkService.RegisterViewPermission(Guid contentPermissionId, Guid permissionId)
    at Telligent.Evolution.Api.Plugins.Bookmarks.BookmarkServicePlugin.PluginManager_AfterInitialization(Object sender, EventArgs e)


    for bookmarks, likes, comments, recommended and so on (I don't use part of them).

    As I understand exceptions related to fields DefaultPermissionId and DefaultContentPermissionId.
    this.BookmarkService.RegisterViewPermission(securedContentType.DefaultContentPermissionId, securedContentType.DefaultPermissionId);

    For first I use my ContentTypeId, for second - my custom Guid for permissions. Also tried DefaultContentPermissionId with ContentTypeId - same result.
    Maybe I missed permissionId registration somethere?
  • Are you also implementing IApplicationType?  ISecuredContentType applies to content, which still requires an application type

  • Former Member
    0 Former Member in reply to Patrick M.

    I created ApplicationType and also implementing it with IContentType (found that aaproach in native applications like blog), coz I need ability to subscribe both custom application and custom content.

    And I recive that exception for both application and content.

  • DefaultPermissionId   is not the ContentTypeId, it is generally a defined "Read" permission Id.
    DefaultContentPermissionId  is the ContentId
    GetSecurableId  returns an applicationId, which is fine if they are the same as content

  • Former Member
    0 Former Member in reply to Patrick M.

    Thank you. now I don't see any errors in logs.

    But have next issue:

    I subscribed to the my application using /api.ashx/v2/content/subscription.json (with myApplicationId and myApplicationTypeId)
    got correct response
    next check all subscribed users by
    Apis.Get<IContentSubscriptions>().SubscribedUsers(myApplicationId)
    and got empty list.

    I see myApplicationId in the db table te_Content_ContentSubscriptions

    Group with this application has all permissions for it.

    As I understand SubscribedUsers also checks some permissions, possible SitePermission.ReadSite. Should I add it somethere? 

     

  • Former Member
    0 Former Member in reply to Former Member

    I found. I have to register permissions for View in IPermissionRegistrar extension

    permissionController.Register(new RoadTestPermission(RoadTestConstants.PermissionItemView, "View RoadTest", "Enables users to view RoadTest.",
    RoadTestConstants.RoadTestItemApplicationTypeId, allowPermissionConfiguration));

    and then use it in ISecuredContentType for an Application:

    public Guid ContentPermissionId => RoadTestConstants.RoadTestItemApplicationTypeId;
    public Guid PermissionId => RoadTestConstants.PermissionItemView;