Ejemplo n.º 1
0
        private async Task <string> Publish(string url, PageModule pagemodule)
        {
            var permissions = UserSecurity.GetPermissionStrings(pagemodule.Module.Permissions);

            foreach (var permissionstring in permissions)
            {
                if (permissionstring.PermissionName == PermissionNames.View)
                {
                    List <string> ids = permissionstring.Permissions.Split(';').ToList();
                    if (!ids.Contains(RoleNames.Everyone))
                    {
                        ids.Add(RoleNames.Everyone);
                    }
                    if (!ids.Contains(RoleNames.Registered))
                    {
                        ids.Add(RoleNames.Registered);
                    }
                    permissionstring.Permissions = string.Join(";", ids.ToArray());
                }
            }
            pagemodule.Module.Permissions = UserSecurity.SetPermissionStrings(permissions);
            await ModuleService.UpdateModuleAsync(pagemodule.Module);

            return(url);
        }
Ejemplo n.º 2
0
        private async Task <string> Publish(string s, PageModule pagemodule)
        {
            var permissions = UserSecurity.GetPermissionStrings(pagemodule.Module.Permissions);

            foreach (var permissionstring in permissions)
            {
                if (permissionstring.PermissionName == PermissionNames.View)
                {
                    List <string> ids = permissionstring.Permissions.Split(';').ToList();
                    if (!ids.Contains(Constants.AllUsersRole))
                    {
                        ids.Add(Constants.AllUsersRole);
                    }
                    if (!ids.Contains(Constants.RegisteredRole))
                    {
                        ids.Add(Constants.RegisteredRole);
                    }
                    permissionstring.Permissions = string.Join(";", ids.ToArray());
                }
            }
            pagemodule.Module.Permissions = UserSecurity.SetPermissionStrings(permissions);
            await ModuleService.UpdateModuleAsync(pagemodule.Module);

            return(NavigateUrl(s, "reload"));
        }
        protected override async Task OnInitializedAsync()
        {
            if (string.IsNullOrEmpty(PermissionNames))
            {
                _permissionnames = Shared.PermissionNames.View + "," + Shared.PermissionNames.Edit;
            }
            else
            {
                _permissionnames = PermissionNames;
            }

            _roles = await RoleService.GetRolesAsync(ModuleState.SiteId);

            _roles.Insert(0, new Role {
                Name = Constants.AllUsersRole
            });

            _permissions = new List <PermissionString>();

            foreach (string permissionname in _permissionnames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                // initialize with admin role
                _permissions.Add(new PermissionString {
                    PermissionName = permissionname, Permissions = Constants.AdminRole
                });
            }

            if (!string.IsNullOrEmpty(Permissions))
            {
                // populate permissions
                foreach (PermissionString permissionstring in UserSecurity.GetPermissionStrings(Permissions))
                {
                    if (_permissions.Find(item => item.PermissionName == permissionstring.PermissionName) != null)
                    {
                        _permissions[_permissions.FindIndex(item => item.PermissionName == permissionstring.PermissionName)].Permissions = permissionstring.Permissions;
                    }

                    if (permissionstring.Permissions.Contains("["))
                    {
                        foreach (string user in permissionstring.Permissions.Split(new char[] { '[' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (user.Contains("]"))
                            {
                                var userid = int.Parse(user.Substring(0, user.IndexOf("]")));
                                if (_users.Where(item => item.UserId == userid).FirstOrDefault() == null)
                                {
                                    _users.Add(await UserService.GetUserAsync(userid, ModuleState.SiteId));
                                }
                            }
                        }
                    }
                }
            }
        }
        private async Task <string> Unpublish(string s, PageModule pagemodule)
        {
            var permissions = UserSecurity.GetPermissionStrings(pagemodule.Module.Permissions);

            foreach (var permissionstring in permissions)
            {
                if (permissionstring.PermissionName == PermissionNames.View)
                {
                    List <string> ids = permissionstring.Permissions.Split(';').ToList();
                    ids.Remove(RoleNames.Everyone);
                    ids.Remove(RoleNames.Registered);
                    permissionstring.Permissions = string.Join(";", ids.ToArray());
                }
            }
            pagemodule.Module.Permissions = UserSecurity.SetPermissionStrings(permissions);
            await ModuleService.UpdateModuleAsync(pagemodule.Module);

            return(NavigateUrl(s, "reload"));
        }
Ejemplo n.º 5
0
        protected virtual List <ActionViewModel> GetActions()
        {
            var actionList = new List <ActionViewModel>();

            if (PageState.EditMode && UserSecurity.IsAuthorized(PageState.User, PermissionNames.Edit, ModuleState.Permissions))
            {
                actionList.Add(new ActionViewModel {
                    Icon = Icons.Cog, Name = "Manage Settings", Action = async(u, m) => await Settings(u, m)
                });

                if (UserSecurity.GetPermissionStrings(ModuleState.Permissions).FirstOrDefault(item => item.PermissionName == PermissionNames.View).Permissions.Split(';').Contains(RoleNames.Everyone))
                {
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.CircleX, Name = "Unpublish Module", Action = async(s, m) => await Unpublish(s, m)
                    });
                }
                else
                {
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.CircleCheck, Name = "Publish Module", Action = async(s, m) => await Publish(s, m)
                    });
                }
                actionList.Add(new ActionViewModel {
                    Icon = Icons.Trash, Name = "Delete Module", Action = async(u, m) => await DeleteModule(u, m)
                });

                if (ModuleState.ModuleDefinition != null && ModuleState.ModuleDefinition.ServerManagerType != "")
                {
                    actionList.Add(new ActionViewModel {
                        Name = ""
                    });
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.CloudUpload, Name = "Import Content", Action = async(u, m) => await EditUrlAsync(u, m.ModuleId, "Import")
                    });
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.CloudDownload, Name = "Export Content", Action = async(u, m) => await EditUrlAsync(u, m.ModuleId, "Export")
                    });
                }

                actionList.Add(new ActionViewModel {
                    Name = ""
                });

                if (ModuleState.PaneModuleIndex > 0)
                {
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.DataTransferUpload, Name = "Move To Top", Action = async(s, m) => await MoveTop(s, m)
                    });
                }

                if (ModuleState.PaneModuleIndex > 0)
                {
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.ArrowThickTop, Name = "Move Up", Action = async(s, m) => await MoveUp(s, m)
                    });
                }

                if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
                {
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.ArrowThickBottom, Name = "Move Down", Action = async(s, m) => await MoveDown(s, m)
                    });
                }

                if (ModuleState.PaneModuleIndex < (ModuleState.PaneModuleCount - 1))
                {
                    actionList.Add(new ActionViewModel {
                        Icon = Icons.DataTransferDownload, Name = "Move To Bottom", Action = async(s, m) => await MoveBottom(s, m)
                    });
                }

                foreach (string pane in PageState.Page.Panes)
                {
                    if (pane != ModuleState.Pane)
                    {
                        actionList.Add(new ActionViewModel {
                            Icon = Icons.AccountLogin, Name = pane + " Pane", Action = async(s, m) => await MoveToPane(s, pane, m)
                        });
                    }
                }
            }

            return(actionList);
        }