Esempio 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();
        }
Esempio 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());
 }
Esempio 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;
        }
Esempio 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();
            }
        }
Esempio 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();
        }
Esempio 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();
            }
        }