November Happy Hour will be moved to Thursday December 5th.

Blog entry 'post comment' button is disabled

Vote:
 

I'm running Relate 2.0 templates on a CMS6 site with Community 4.0.517.255. Customer is using their own eDirectory security provider, not EPiServerCommon. All of the users from eDirectory are created ad Community users by a scheduled jobs that's running once a day.

Production enviroment:

'Post comment' button is disabled on blog entries, and hidden on images gallery images. So is ratings. Posting comments only works on blogentries and images that are owned by user.

Development enviroment:

'Post comment' and rating is visible for 'admin' (member of 'CommunityAdmins') and my local windows administrator, but not for my Community 'dummy' user. I'm running Multiplexing with Windows as first and EPiServerCommon as second provider.

I've found out that the bold line (BlogEntry.ascx.cs line 122) return false: btnPostComment.Enabled = (CurrentUser != null ? EntitySecurityHandler.Instance.CheckAccess(CurrentEntry, CurrentUser, entryAccessRights) : false);

In Reflector CheckAccess:

public virtual bool CheckAccess(ISecurableEntity securableEntity, IUser user, IAccessRights accessRightsMask)
{
    IAccessRights totalAccessRights;
    EntityValidator.ValidateIsCommittedEntity(securableEntity, "securableEntity");
    EntityValidator.ValidateIsNotNull(accessRightsMask, "accessRightsMask");
    if (!accessRightsMask.GetType().IsAssignableFrom(securableEntity.AccessRightsType))
    {
        throw new ArgumentException(string.Format("The access rights mask is of a different type than what is applicable to {0}", securableEntity.GetType().ToString()), "accessRightsMask");
    }
    if (user != null)
    {
        totalAccessRights = this.GetTotalAccessRights(securableEntity, user);
    }
    else
    {
        totalAccessRights = this.GetTotalAccessRights(securableEntity, Settings.DefaultSecurity.GetGroup(EPiServerCommonSection.Instance.SecurityElement.AnonymousGroupId));
    }
    return ((totalAccessRights.AccessLevel & accessRightsMask.AccessLevel) == accessRightsMask.AccessLevel);
}

I've tried debugging via .Net Reflector, but can't seem to evaluate anything inside EPiServer.Common.Framework.Impl.EntitySecurityHandler.

What I need is good suggestions on how to find out what access rights that are missing for user! :)

#45587
Nov 10, 2010 10:16
Vote:
 

Make sure that you new users are in the correct group I remember we hade the same problem within episerver where we had EPiServer group that was supposed to be the CommunityMembers group. Therefore we hade to change the groupname in web.config and also reflect this group in the tables where they are using the CommunityMembers group so that it said EPiServer All instead.

If i remember correctly there is something about this in the article about upgrading a site from Relate 1 to Relate 2!?

 

/Eric

#45600
Nov 10, 2010 13:04
Vote:
 

Thanks for the clue Eric! :)

Scheduled job is now adding all created users to 'CommunityMembers'. Comment button and rating are both available. :) I just copied code from Templates\RelatePlus\CommunityModules\CommunitySecurityModule.cs:

/// <summary>
        /// Adds the created user to the community group specified in Web.config
        /// </summary>
        /// <param name="addedUser">The user</param>
        private static void DefaultSecurity_CreatedUser(IUser addedUser)
        {
            // Add user to the community members group
            IGroup group = CommunitySystem.CurrentContext.DefaultSecurity.GetGroupByName(_community_Members);
            addedUser = (IUser)addedUser.Clone();
            addedUser.Groups.Add(group);

            // Update the user
            CommunitySystem.CurrentContext.DefaultSecurity.UpdateUser(addedUser);

            // Set access rights to the newly created user
            // Access right for anonymous users
            ReadModifyRemoveAccessRights anonAccessRights = new ReadModifyRemoveAccessRights()
            {
                Read = true,
                Modify = false,
                Remove = false
            };
            EntitySecurityHandler.Instance.SetAccessRights(addedUser, AnonymousGroup, anonAccessRights);

            // Access right for community members
            ReadModifyRemoveAccessRights communityMembersAccessRights = new ReadModifyRemoveAccessRights()
            {
                Read = true,
                Modify = false,
                Remove = false
            };
            EntitySecurityHandler.Instance.SetAccessRights(addedUser, group, communityMembersAccessRights);

            // Access rights for administrators
            ReadModifyRemoveAccessRights adminAccessRights = new ReadModifyRemoveAccessRights()
            {
                Read = true,
                Modify = true,
                Remove = true
            };
            EntitySecurityHandler.Instance.SetAccessRights(addedUser, AdministratorsGroup, adminAccessRights);

            // Access rights for the added user
            ReadModifyRemoveAccessRights userAccessRights = new ReadModifyRemoveAccessRights()
            {
                Read = true,
                Modify = true,
                Remove = true
            };
            EntitySecurityHandler.Instance.SetAccessRights(addedUser, addedUser, userAccessRights);

            // Access rights for moderator
            ReadModifyRemoveAccessRights moderatorAccessRights = new ReadModifyRemoveAccessRights()
            {
                Read = true,
                Modify = true,
                Remove = true
            };
            EntitySecurityHandler.Instance.SetAccessRights(addedUser, ModeratorsGroup, moderatorAccessRights);
        }

        private static IGroup AnonymousGroup
        {
            get
            {
                return EPiServer.Common.Settings.DefaultSecurity.GetGroup(EPiServerCommonSection.Instance.SecurityElement.AnonymousGroupId);
            }
        }

        private static IGroup AdministratorsGroup
        {
            get
            {
                return SecurityHandler.Instance.GetGroupByName("Administrators");
            }
        }

        private static IGroup ModeratorsGroup
        {
            get
            {
                return SecurityHandler.Instance.GetGroupByName("CommunityModerators");
            }
        }

#45608
Nov 10, 2010 15:07
Vote:
 

Glad to help :)

And thanks for the code will probably be helpfull!!

#45615
Nov 10, 2010 20:37
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.