Esempio n. 1
0
        public static bool HasUnlockAccess(SC.Data.Items.Item item, SC.Security.Accounts.User user = null)
        {
            Assert.ArgumentNotNull(item, "item");

            if (user == null)
            {
                user = SC.Context.User;
                Assert.IsNotNull(user, "context user");
            }

            if (user.IsAdministrator)
            {
                return(true);
            }

            SC.Security.AccessControl.AccessRight checkIn = SC.Security.AccessControl.AccessRight.FromName("item:checkin");

            if (checkIn != null)
            {
                return(SC.Security.AccessControl.AuthorizationManager.IsAllowed(item, checkIn, user));
            }

            SC.Security.Accounts.Role control = SC.Security.Accounts.Role.FromName("sitecore\\Sitecore Client Maintaining");

            return(SC.Security.Accounts.Role.Exists(control.Name) && SC.Security.Accounts.RolesInRolesManager.IsUserInRole(SC.Context.User, control, true /*includeIndirectMembership*/));
        }
        /// <summary>
        /// Gets a <see cref="UserGroup"/> by <see cref="UserGroup.Name"/>.
        /// </summary>
        /// <param name="externalId">Name of the user group.</param>
        /// <returns></returns>
        public virtual UserGroup GetUserGroup(string externalId)
        {
            UserGroup userGroup = UserGroup.SingleOrDefault(x => x.ExternalId.ToUpper() == externalId.ToUpper());

            if (userGroup != null)
            {
                userGroup.Name = userGroup.ExternalId;
                return(userGroup);
            }

            Domain sitecoreDomain = Domain.GetDomain(_sitecoreContext.BackendDomainName);

            Role sitecoreUserGroup = sitecoreDomain.GetRoles().FirstOrDefault(x => x.DisplayName == externalId);

            if (sitecoreUserGroup == null)
            {
                throw new NullReferenceException(string.Format("'sitecore role' is null. For: '{0}'", externalId));
            }

            var newUserGroup = MapExternalUserGroupToInternalUserGroup(externalId);

            newUserGroup.Save();

            return(newUserGroup);
        }