Пример #1
0
        public static void OnFirstInit(IPermissionService permissionService, IGenericRepository <Role> roleGR)
        {
            var pupilPerms = new Permission[] {
                new Permission {
                    Name = "GetPupilPanel"
                },
                new Permission {
                    Name = "EditSubject"
                },
            };

            var adminPerms = new Permission[] {
                new Permission {
                    Name = "GetAdminPanel"
                },
                new Permission {
                    Name = "GetGlobalizationTab"
                },

                new Permission {
                    Name = "GetLanguagesEditTab"
                },
                new Permission {
                    Name = "CreateLanguage"
                },
                new Permission {
                    Name = "RemoveLanguage"
                },
                new Permission {
                    Name = "EditLanguage"
                },

                new Permission {
                    Name = "GetStringsEditTab"
                },
                new Permission {
                    Name = "UpdateBaseUpdateId"
                },
                new Permission {
                    Name = "EditGbStrings"
                },

                new Permission {
                    Name = "GetAllUsers"
                },
                new Permission {
                    Name = "EditUser"
                },
                new Permission {
                    Name = "BanUser"
                },
                new Permission {
                    Name = "UnbanUser"
                }
            };

            permissionService.AddPermissions(adminPerms.Concat(pupilPerms));

            var admRole = roleGR.GetAll(x => x.Name == "Admin").FirstOrDefault();

            admRole.DefaultPermissions = adminPerms.Select(x => new DefaultRolePermission {
                Permission = x
            }).ToList();
            roleGR.Update(admRole);

            var pupilRole = roleGR.GetAll(x => x.Name == "Pupil").FirstOrDefault();

            pupilRole.DefaultPermissions = pupilPerms.Select(x => new DefaultRolePermission {
                Permission = x
            }).ToList();
            roleGR.Update(pupilRole);

            permissionService.AddUserPermissions(new User {
                Id = "admin"
            }, adminPerms.Concat(pupilPerms));
        }