Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Как программно из C# задать права на сайт определенному пользователю

$
0
0
Hi!
I would go with the groups and worked on group level:
        /// <summary>
        /// Grant access to perspectives for user group, ex. var  { "ContentPerspective", "MediaPerspective" }
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="perspectives"></param>
        public static void SetAccess(Guid groupId, List<string> perspectives)
        {
            IEnumerable<EntityToken> perspectiveEntityTokens = ElementFacade.GetPerspectiveElementsWithNoSecurity().Select(f => f.ElementHandle.EntityToken).Where(f => perspectives.Contains(f.Id));
            UserGroupPerspectiveFacade.SetEntityTokens(groupId, perspectiveEntityTokens);
        }

        /// <summary>
        /// Set permissions for a group, ex. var dataPermissionTypes = new [] { PermissionType.Read, PermissionType.Edit };
        /// </summary>
        /// <param name="dataItem"></param>
        /// <param name="groupId"></param>
        /// <param name="permissionType"></param>
        public static void SetPermissions(IData dataItem, Guid groupId, PermissionType[] permissionType)
        {
            string serializedEntityToken = EntityTokenSerializer.Serialize(dataItem.GetDataEntityToken());
            UserGroupPermissionDefinition userGroupPermissionDefinition = new ConstructorBasedUserGroupPermissionDefinition(groupId, permissionType, serializedEntityToken);
            PermissionTypeFacade.SetUserGroupPermissionDefinition(userGroupPermissionDefinition);
        }
and than:
                //Give perspective access to "Content" and "Media" for a user group
                var perspectives = new List<string> { "ContentPerspective", "MediaPerspective", "Reports", "Settings" };
                UserGroups.SetAccess(userGroup.Id, perspectives);

                //Give edit and read access to the specific data item
                UserGroups.SetPermissions(myDataItem, userGroup.Id, new[] { PermissionType.Read, PermissionType.Edit });

by the way, there is ready to use product: http://www.composite.net/Products/Add-ons/All/Composite.Tools.SubsiteManager

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>