Exemple #1
0
 public void AddGroup(IReadOnlyUserGroup group)
 {
     if (_userGroups.Add(group))
     {
         //reset this flag so it's rebuilt with the assigned groups
         _allowedSections = null;
         OnPropertyChanged(Ps.Value.UserGroupsSelector);
     }
 }
Exemple #2
0
 // Umbraco.Code.MapAll -ContentStartNode -UserCount -MediaStartNode -Key -Sections
 // Umbraco.Code.MapAll -Notifications -Udi -Trashed -AdditionalData
 private void Map(IReadOnlyUserGroup source, UserGroupBasic target, MapperContext context)
 {
     target.Alias    = source.Alias;
     target.Icon     = source.Icon;
     target.Id       = source.Id;
     target.Name     = source.Name;
     target.ParentId = -1;
     target.Path     = "-1," + source.Id;
     MapUserGroupBasic(target, source.AllowedSections, source.StartContentId, source.StartMediaId, context);
 }
 private BackOfficeIdentityUser()
 {
     _startMediaIds            = new int[] { };
     _startContentIds          = new int[] { };
     _groups                   = new IReadOnlyUserGroup[] { };
     _allowedSections          = new string[] { };
     _culture                  = Configuration.GlobalSettings.DefaultUILanguage;
     _groups                   = new IReadOnlyUserGroup[0];
     _roles                    = new ObservableCollection <IdentityUserRole <string> >();
     _roles.CollectionChanged += _roles_CollectionChanged;
 }
Exemple #4
0
        public void Test()
        {
            IContentType contentType = Mock.Of <IContentType>();

            Mock.Get(contentType).Setup(x => x.Alias).Returns("type1");
            IContent content = Mock.Of <IContent>();

            Mock.Get(content).Setup(x => x.ContentType).Returns(new SimpleContentType(contentType));

            IReadOnlyUserGroup group1 = Mock.Of <IReadOnlyUserGroup>();

            Mock.Get(group1).Setup(x => x.Alias).Returns("group1");
            IReadOnlyUserGroup group2 = Mock.Of <IReadOnlyUserGroup>();

            Mock.Get(group2).Setup(x => x.Alias).Returns("group2");

            // no rule = ok
            AssertDefinition(content, true, Array.Empty <string>(), new[] { group1, group2 });

            // wildcards = ok
            AssertDefinition(content, true, new[] { "+content/*" }, new[] { group1, group2 });
            AssertDefinition(content, false, new[] { "+media/*" }, new[] { group1, group2 });

            // explicitly enabling / disabling
            AssertDefinition(content, true, new[] { "+content/type1" }, new[] { group1, group2 });
            AssertDefinition(content, false, new[] { "-content/type1" }, new[] { group1, group2 });

            // when there are type rules, failing to approve the type = no app
            AssertDefinition(content, false, new[] { "+content/type2" }, new[] { group1, group2 });
            AssertDefinition(content, false, new[] { "+media/type1" }, new[] { group1, group2 });

            // can have multiple rule, first one that matches = end
            AssertDefinition(content, false, new[] { "-content/type1", "+content/*" }, new[] { group1, group2 });
            AssertDefinition(content, true, new[] { "-content/type2", "+content/*" }, new[] { group1, group2 });
            AssertDefinition(content, true, new[] { "+content/*", "-content/type1" }, new[] { group1, group2 });

            // when there are role rules, failing to approve a role = no app
            AssertDefinition(content, false, new[] { "+role/group33" }, new[] { group1, group2 });

            // wildcards = ok
            AssertDefinition(content, true, new[] { "+role/*" }, new[] { group1, group2 });

            // explicitly enabling / disabling
            AssertDefinition(content, true, new[] { "+role/group1" }, new[] { group1, group2 });
            AssertDefinition(content, false, new[] { "-role/group1" }, new[] { group1, group2 });

            // can have multiple rule, first one that matches = end
            AssertDefinition(content, true, new[] { "+role/group1", "-role/group2" }, new[] { group1, group2 });

            // mixed type and role rules, both are evaluated and need to match
            AssertDefinition(content, true, new[] { "+role/group1", "+content/type1" }, new[] { group1, group2 });
            AssertDefinition(content, false, new[] { "+role/group1", "+content/type2" }, new[] { group1, group2 });
            AssertDefinition(content, false, new[] { "+role/group33", "+content/type1" }, new[] { group1, group2 });
        }
        public int RenameMediaHome(TenantData tenant, TenantUser tenantUser)
        {
            var home = TenantHelper.GetCurrentTenantHome(ConnectorContext.ContentService, tenant.TenantUId.ToString());

            if (home == null)
            {
                throw new TenantException(ExceptionCode.TenantNotFound.CodeToString(), ExceptionCode.TenantNotFound, tenant.TenantUId);
            }

            IMedia             mediaHome = null;
            IReadOnlyUserGroup group     = null;

            if (tenantUser != null)
            {
                var uService = ConnectorContext.UserService;
                var user     = uService.GetByUsername(tenantUser.Username);
                group     = user.Groups.ToList()[0];
                mediaHome = mediaService.GetById(group.StartMediaId.Value);
            }
            else
            {
                mediaHome = mediaService.GetByLevel(1).SingleOrDefault(x => x.Name.Contains(tenant.Name));
            }

            if (mediaHome == null)
            {
                string mediaId = group?.StartMediaId.Value.ToString() ?? tenant.Name;
                //string mediaId = group?.StartMediaId.Value.ToString() ?? tenant.BrandName;
                throw new TenantException(ExceptionCode.MediaNodeDoesNotExist.CodeToString(), ExceptionCode.MediaNodeDoesNotExist, tenant.TenantUId, mediaId);
            }

            try
            {
                if (!mediaHome.Name.Equals(tenant.Name))
                {
                    mediaHome.Name = tenant.Name;
                    //mediaHome.Name = tenant.BrandName;
                    mediaService.Save(mediaHome);
                    ConnectorContext.AuditService.Add(AuditType.Save, -1, mediaHome.Id, "Media Folder", $"Media home for {tenant.TenantUId} has been renamed");
                }

                return(mediaHome.Id);
            }
            catch (System.Exception ex)
            {
                logger.Error(typeof(HomeMediaNode), ex.Message);
                logger.Error(typeof(HomeMediaNode), ex.StackTrace);
                throw;
            }
        }
 /// <summary>
 /// Creates an existing user with the specified groups
 /// </summary>
 /// <param name="userId"></param>
 /// <param name="groups"></param>
 public BackOfficeIdentityUser(int userId, IEnumerable <IReadOnlyUserGroup> groups)
 {
     _startMediaIds   = new int[] { };
     _startContentIds = new int[] { };
     _groups          = new IReadOnlyUserGroup[] { };
     _allowedSections = new string[] { };
     _culture         = Configuration.GlobalSettings.DefaultUILanguage;
     _groups          = groups.ToArray();
     _roles           = new ObservableCollection <IdentityUserRole <string> >(_groups.Select(x => new IdentityUserRole <string>
     {
         RoleId = x.Alias,
         UserId = userId.ToString()
     }));
     _roles.CollectionChanged += _roles_CollectionChanged;
 }
 public static bool IsSystemUserGroup(this IReadOnlyUserGroup group) =>
 IsSystemUserGroup(group.Alias);