Exemplo n.º 1
0
        // Enable initialization with an instance of ApplicationRole:
        public SelectEntityRolesViewModel(string RoleName)
            : this()
        {
            this.RoleName = RoleName;
            var Db              = new PermissionContext();
            var permissions     = Db.Permissions.ToList().Where(p => p.RoleName == RoleName);
            var listprivileges  = Db.AdminPrivileges.ToList().Where(p => p.RoleName == RoleName);
            var IsAppHeader     = false;
            var IsDefaultHeader = false;
            var rowcnt          = 0;

            foreach (var ent in GeneratorBase.MVC.ModelReflector.Entities.Where(p => !p.IsAdminEntity))
            {
                if (ent.Name.ToUpper() == "PERMISSION")
                {
                    continue;
                }

                if (!IsAppHeader && !ent.IsDefault && rowcnt == 0)
                {
                    IsAppHeader = true;
                    rowcnt++;
                }
                else
                {
                    IsAppHeader = false;
                }
                if (!IsDefaultHeader && ent.IsDefault && rowcnt == 1)
                {
                    IsDefaultHeader = true;
                    rowcnt++;
                }
                else
                {
                    IsDefaultHeader = false;
                }

                var rvm = new SelectPermissionEditorViewModel(ent.Name, IsAppHeader, IsDefaultHeader);

                this.Entities.Add(rvm);
            }
            foreach (var perm in permissions)
            {
                var checkUserRole =
                    this.Entities.ToList().Find(r => r.EntityName == perm.EntityName);
                if (checkUserRole == null)
                {
                    continue;
                }
                if (perm.CanEdit)
                {
                    checkUserRole.CanEdit = true;
                }
                if (perm.CanDelete)
                {
                    checkUserRole.CanDelete = true;
                }
                if (perm.CanView)
                {
                    checkUserRole.CanView = true;
                }
                if (perm.CanAdd)
                {
                    checkUserRole.CanAdd = true;
                }
                checkUserRole.IsOwner          = perm.IsOwner != null ?perm.IsOwner.Value:false;
                checkUserRole.SelfRegistration = perm.SelfRegistration != null ? perm.SelfRegistration.Value : false;
                checkUserRole.UserAssociation  = perm.UserAssociation;
                //code for verb action security
                checkUserRole.Verbs = perm.Verbs;
                //
            }
            //foreach (var item in Enum.GetValues(typeof(AdminFeatures)))
            foreach (var item in (new AdminFeaturesDictionary()).getDictionary())
            {
                var privilege = listprivileges.FirstOrDefault(p => p.AdminFeature == item.Key);
                if (privilege != null)
                {
                    this.privileges.Add(privilege);
                }
                else
                {
                    var obj = new PermissionAdminPrivilege();
                    obj.RoleName     = this.RoleName;
                    obj.AdminFeature = item.Key;
                    obj.IsAllow      = false;
                    obj.IsAdd        = false;
                    obj.IsEdit       = false;
                    obj.IsDelete     = false;
                    this.privileges.Add(obj);
                }
            }
        }
Exemplo n.º 2
0
        //
        private CommonFunction()
        {
            var appsettinglist = (new ApplicationContext(new SystemUser())).AppSettings;

            reportPath             = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "ReportPath".ToLower()).Value;
            reportUser             = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "ReportUser".ToLower()).Value;
            reportPass             = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "ReportPass".ToLower()).Value;
            reportFolder           = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "ReportFolder".ToLower()).Value;
            administratorRoles     = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "AdministratorRoles".ToLower()).Value;
            useActiveDirectory     = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "UseActiveDirectory".ToLower()).Value;
            useActiveDirectoryRole = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "UseActiveDirectoryRole".ToLower()).Value;
            domainName             = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "DomainName".ToLower()).Value;
            needSharedUserSystem   = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "NeedSharedUserSystem".ToLower()).Value;
            server  = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "server".ToLower()).Value;
            appURL  = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "AppURL".ToLower()).Value;
            appName = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "AppName".ToLower()).Value;
            multipleRoleSelection          = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "MultipleRoleSelection".ToLower()).Value;
            enablePrototypingTool          = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "EnablePrototypingTool".ToLower()).Value;
            gpsenabled                     = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "GPSEnabled".ToLower()).Value;
            applicationSessiontimeout      = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "ApplicationSessionTimeOut".ToLower()).Value;
            applicationSessiontimeoutAlert = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "ApplicationSessionTimeOutAlert".ToLower()).Value;
            Glimpse         = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "Glimpse".ToLower()).Value;
            createanAccount = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "CreateAnAccount".ToLower()).Value;
            //GA Seetings
            enableGA            = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "Enable google analytics".ToLower()).Value;
            trackingID          = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "Tracking ID".ToLower()).Value;
            customdimensionname = appsettinglist.FirstOrDefault(p => p.Key.ToLower() == "Custom Dimension Name".ToLower()).Value;
            //

            var roleContext = new ApplicationDbContext(true);

            if (roleContext.Roles.FirstOrDefault(p => p.Name == "ReadOnly") != null)
            {
                using (var permissionContext = new PermissionContext())
                {
                    if (permissionContext.Permissions.Where(p => p.RoleName == "ReadOnly").Count() == 0)
                    {
                        foreach (var ent in ModelReflector.Entities)
                        {
                            Permission permission = new Permission();
                            permission.CanAdd           = false;
                            permission.CanDelete        = false;
                            permission.CanView          = true;
                            permission.CanEdit          = false;
                            permission.IsOwner          = false;
                            permission.SelfRegistration = false;
                            permission.EntityName       = ent.Name;
                            permission.RoleName         = "ReadOnly";
                            permissionContext.Permissions.Add(permission);
                        }
                        permissionContext.SaveChanges();
                    }
                }
            }
            //
            if (roleContext.Roles.FirstOrDefault(p => p.Name == "CanEdit") != null)
            {
                using (var permissionContext1 = new PermissionContext())
                {
                    if (permissionContext1.Permissions.Where(p => p.RoleName == "CanEdit").Count() == 0)
                    {
                        foreach (var ent in ModelReflector.Entities)
                        {
                            Permission permission = new Permission();
                            permission.CanAdd           = true;
                            permission.CanDelete        = false;
                            permission.CanView          = true;
                            permission.CanEdit          = true;
                            permission.IsOwner          = false;
                            permission.SelfRegistration = false;
                            permission.EntityName       = ent.Name;
                            permission.RoleName         = "CanEdit";
                            permissionContext1.Permissions.Add(permission);
                        }
                        permissionContext1.SaveChanges();
                    }
                }
            }
            if (roleContext.Roles.FirstOrDefault(p => p.Name == "Tenant-Admin-Template") != null)
            {
                using (var permissionContextTenantAdmin = new PermissionContext())
                {
                    if (permissionContextTenantAdmin.Permissions.Where(p => p.RoleName == "Tenant-Admin-Template").Count() == 0)
                    {
                        foreach (var ent in ModelReflector.Entities)
                        {
                            Permission permission = new Permission();
                            permission.CanAdd           = true;
                            permission.CanDelete        = false;
                            permission.CanView          = true;
                            permission.CanEdit          = true;
                            permission.IsOwner          = false;
                            permission.SelfRegistration = false;
                            permission.EntityName       = ent.Name;
                            permission.RoleName         = "Tenant-Admin-Template";
                            permissionContextTenantAdmin.Permissions.Add(permission);
                        }
                        PermissionAdminPrivilege permissionRole = new PermissionAdminPrivilege();
                        permissionRole.AdminFeature = "Role";
                        permissionRole.IsAdd        = true;
                        permissionRole.IsAllow      = true;
                        permissionRole.IsDelete     = true;
                        permissionRole.IsEdit       = true;
                        permissionRole.RoleName     = "Tenant-Admin-Template";
                        permissionContextTenantAdmin.AdminPrivileges.Add(permissionRole);

                        PermissionAdminPrivilege permissionUser = new PermissionAdminPrivilege();
                        permissionUser.AdminFeature = "User";
                        permissionUser.IsAdd        = true;
                        permissionUser.IsAllow      = true;
                        permissionUser.IsDelete     = true;
                        permissionUser.IsEdit       = true;
                        permissionUser.RoleName     = "Tenant-Admin-Template";
                        permissionContextTenantAdmin.AdminPrivileges.Add(permissionUser);

                        PermissionAdminPrivilege permissionAssignUserRole = new PermissionAdminPrivilege();
                        permissionAssignUserRole.AdminFeature = "AssignUserRole";
                        permissionAssignUserRole.IsAdd        = true;
                        permissionAssignUserRole.IsAllow      = true;
                        permissionAssignUserRole.IsDelete     = true;
                        permissionAssignUserRole.IsEdit       = true;
                        permissionAssignUserRole.RoleName     = "Tenant-Admin-Template";
                        permissionContextTenantAdmin.AdminPrivileges.Add(permissionAssignUserRole);

                        PermissionAdminPrivilege permissionRoleEntityPermission = new PermissionAdminPrivilege();
                        permissionRoleEntityPermission.AdminFeature = "RoleEntityPermission";
                        permissionRoleEntityPermission.IsAdd        = true;
                        permissionRoleEntityPermission.IsAllow      = true;
                        permissionRoleEntityPermission.IsDelete     = true;
                        permissionRoleEntityPermission.IsEdit       = true;
                        permissionRoleEntityPermission.RoleName     = "Tenant-Admin-Template";
                        permissionContextTenantAdmin.AdminPrivileges.Add(permissionRoleEntityPermission);

                        PermissionAdminPrivilege permissionUserInterfaceSetting = new PermissionAdminPrivilege();
                        permissionUserInterfaceSetting.AdminFeature = "UserInterfaceSetting";
                        permissionUserInterfaceSetting.IsAdd        = true;
                        permissionUserInterfaceSetting.IsAllow      = true;
                        permissionUserInterfaceSetting.IsDelete     = true;
                        permissionUserInterfaceSetting.IsEdit       = true;
                        permissionUserInterfaceSetting.RoleName     = "Tenant-Admin-Template";
                        permissionContextTenantAdmin.AdminPrivileges.Add(permissionUserInterfaceSetting);

                        permissionContextTenantAdmin.SaveChanges();
                    }
                }
            }
        }