Exemplo n.º 1
0
        public void CreateRole(Role role)
        {
            LoadMetadata();

            RoleMetadata md;
            List<RoleMetadata> mds = this.metadata.Roles.Where(m => m.Id == role.Id).ToList();
            if (mds.Count == 1)
            {
                md = mds[0];
            }
            else
            {
                md = new RoleMetadata();
                this.metadata.Roles.Add(md);
            }

            TranslateToMetadata(md, role);

            SaveMetadata();
        }
Exemplo n.º 2
0
 private static void TranslateToMetadata(RoleMetadata rm, Role role)
 {
     rm.AssignUnassignRole = role.AssignUnassignRole;
     rm.CanCreateRoot = role.CanCreateRoot;
     rm.CanManageSubRoles = role.CanManageSubRoles;
     rm.CanCreateUsers = role.CanCreateUsers;
     rm.ChildRoles = new Collection<ChildId>(role.ChildRoles.Select(id => new ChildId(id)).ToList());
     rm.DataEntities = new Collection<EntityId>(role.DataEntities.Select(id => new EntityId(id)).ToList());
     rm.DataEntityPermission = role.DataEntityPermission;
     rm.Id = role.Id;
     rm.IsRoot = role.IsRoot;
     rm.Name = ConvertBinary(role.Name);
     rm.Users = new Collection<ChildId>(role.Users.Select(id => new ChildId(id)).ToList());
 }
Exemplo n.º 3
0
        private static Role TranslateFromMetadata(RoleMetadata rm)
        {
            Role r = new Role();

            r.AssignUnassignRole = rm.AssignUnassignRole;
            r.CanCreateRoot = rm.CanCreateRoot;
            r.CanManageSubRoles = rm.CanManageSubRoles;
            r.CanCreateUsers = rm.CanCreateUsers;
            r.ChildRoles = rm.ChildRoles.Select(c => c.Id).ToList();
            r.DataEntities = rm.DataEntities.Select(d => d.Id).ToList();
            r.DataEntityPermission = rm.DataEntityPermission;
            r.Id = rm.Id;
            r.IsRoot = rm.IsRoot;
            r.Name = ConvertBinary(rm.Name);
            r.Users = rm.Users.Select(u => u.Id).ToList();

            return r;
        }
Exemplo n.º 4
0
        public void UpdateRole(Role role)
        {
            LoadMetadata();

            List<RoleMetadata> mds = this.metadata.Roles.Where(m => m.Id == role.Id).ToList();
            if (mds.Count == 1)
            {
                TranslateToMetadata(mds[0], role);
                SaveMetadata();
            }
        }
Exemplo n.º 5
0
        public void InitializeSystem(User dataOwner, Role dataOwnerRootRole)
        {
            this.metadata = new StorageMetadata();
            this.metadata.DataOwnerUserId = dataOwner.Id;
            this.metadata.DataOwnerRoleId = dataOwnerRootRole.Id;

            CreateUser(dataOwner);
            CreateRole(dataOwnerRootRole);

            SaveMetadata();
        }
Exemplo n.º 6
0
        public void DeleteRole(Role role)
        {
            LoadMetadata();

            List<RoleMetadata> mds = this.metadata.Roles.Where(m => m.Id == role.Id).ToList();
            if (mds.Count == 1)
            {
                this.metadata.Roles.Remove(mds[0]);
                SaveMetadata();
            }
        }