예제 #1
0
        public async Task <ActionResult> RemovePage(Guid pageGuid)
        {
            PageDefinition page = page = await PageDefinition.LoadAsync(pageGuid);

            if (page == null)
            {
                throw new InternalError("Page {0} does not exist", pageGuid);
            }
            if (!page.IsAuthorized_Remove())
            {
                return(NotAuthorized());
            }
            await PageDefinition.RemovePageDefinitionAsync(pageGuid);

            return(Redirect((string)null));
        }
예제 #2
0
        public async Task <ActionResult> Remove(string pageName)
        {
            if (string.IsNullOrWhiteSpace(pageName))
            {
                throw new Error(this.__ResStr("noPageName", "No page name specified"));
            }
            PageDefinition page = await PageDefinition.LoadFromUrlAsync(pageName);

            if (page == null)
            {
                throw new Error(this.__ResStr("noPage", "Page \"{0}\" not found", pageName));
            }

            await PageDefinition.RemovePageDefinitionAsync(page.PageGuid);

            return(Reload(null, Reload: ReloadEnum.ModuleParts));
        }
예제 #3
0
        private async Task ExtractPageSectionAsync(List <string> lines, bool build)
        {
            for (; lines.Count > 0;)
            {
                // get the menu path (site url)
                string urlLine = lines.First();
                if (urlLine.StartsWith("::"))
                {
                    break; // start of a new section
                }
                ++_LineCounter; lines.RemoveAt(0);
                if (urlLine.Trim() == "")
                {
                    continue;
                }
                string[] s = urlLine.Split(new char[] { ' ' }, 2);
                if (s.Length != 2)
                {
                    throw TemplateError("Url {0} invalid", urlLine);
                }

                string user = s[0].Trim();
                string url  = s[1].Trim();

                // validate url
                if (url.Length == 0 || url[0] != '/')
                {
                    throw TemplateError("Url must start with / and can't be indented");
                }

                PageDefinition page = null;
                if (build)
                {
                    page = await PageDefinition.CreatePageDefinitionAsync(url);
                }
                else
                {
                    page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page != null)
                    {
                        await PageDefinition.RemovePageDefinitionAsync(page.PageGuid);
                    }
                    page = new PageDefinition();
                }
                _CurrentPage = page;
                _CurrentUrl  = url;

                while (TryPageTitle(page, lines) || TryPageDescription(page, lines))
                {
                    ;
                }

                // Get the Menu Text
                if (lines.Count < 1)
                {
                    throw TemplateError("Menu missing");
                }
                string menu = lines.First(); ++_LineCounter; lines.RemoveAt(0);
                if (string.IsNullOrWhiteSpace(menu))
                {
                    throw TemplateError("Menu missing");
                }
                if (!char.IsWhiteSpace(menu[0]))
                {
                    throw TemplateError("Menu line must be indented");
                }
                menu = menu.Trim();

                // add a menu entry to the site menu
                if (menu != "-")
                {
                    if (build)
                    {
                        ModuleAction action = await AddMenuAsync(menu);

                        //if (string.IsNullOrWhiteSpace(action.Url)) // I don't remember why this was here
                        action.Url = url;
                    }
                    else
                    {
                        await RemoveMenuAsync(menu);
                    }
                }

                // Get the skin
                if (lines.Count < 1)
                {
                    throw TemplateError("Skin missing");
                }
                string skin = lines.First(); ++_LineCounter; lines.RemoveAt(0);
                if (string.IsNullOrWhiteSpace(skin))
                {
                    throw TemplateError("Skin missing");
                }
                if (!char.IsWhiteSpace(skin[0]))
                {
                    throw TemplateError("Skin line must be indented");
                }
                skin = skin.Trim();
                if (skin == "-")
                {
                    skin = ",,,";
                }
                string[] skinparts = skin.Split(new char[] { ',' });
                if (skinparts.Length != 4)
                {
                    throw TemplateError("Invalid skin format");
                }

                page.SelectedSkin.Collection = skinparts[0].Trim();
                if (page.SelectedSkin.Collection == "-")
                {
                    page.SelectedSkin.Collection = null;
                }
                page.SelectedSkin.FileName        = skinparts[1].Trim();
                page.SelectedPopupSkin.Collection = skinparts[2].Trim();
                if (page.SelectedPopupSkin.Collection == "-")
                {
                    page.SelectedPopupSkin.Collection = null;
                }
                page.SelectedPopupSkin.FileName = skinparts[3].Trim();

                SerializableList <PageDefinition.AllowedRole> roles = new SerializableList <PageDefinition.AllowedRole>();
                switch (user)
                {
                case "Administrator":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "User":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetUserRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "Anonymous":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAnonymousRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "Anonymous+User":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAnonymousRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetUserRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                default:
                    throw TemplateError("User {0} invalid", user);
                }
                page.AllowedRoles = roles;

                // Get zero, one or more modules (add to Main section)
                for (; lines.Count > 0;)
                {
                    string modsLine = lines.First();
                    if (string.IsNullOrWhiteSpace(modsLine))
                    {
                        ++_LineCounter; lines.RemoveAt(0);
                        continue;
                    }
                    if (!char.IsWhiteSpace(modsLine[0]))
                    {
                        break;// not a module - module lines must be indented
                    }
                    // Load assembly
                    ++_LineCounter; lines.RemoveAt(0);// accept as module line
                    string[] parts  = modsLine.Split(new char[] { ':' });
                    string   pane   = null;
                    string   modDef = null;
                    if (parts.Length == 1)
                    {
                        pane   = Globals.MainPane;
                        modDef = parts[0].Trim();
                    }
                    else if (parts.Length == 2)
                    {
                        pane = parts[0].Trim();
                        if (pane == "-")
                        {
                            pane = Globals.MainPane;
                        }
                        modDef = parts[1].Trim();
                    }
                    else
                    {
                        throw TemplateError("Invalid \"pane: module definition\"");
                    }
                    ModuleDefinition mod = await EvaluateModuleAsmTypeExpression(modDef);

                    page.AddModule(pane, mod);

                    for (; lines.Count > 0;)
                    {
                        // add variable customizations (if any)
                        string varLine = lines.First();
                        if (string.IsNullOrWhiteSpace(varLine))
                        {
                            ++_LineCounter; lines.RemoveAt(0);
                            continue;
                        }
                        // if this line is more indented than the module line, it must be a variable line
                        if (varLine.Length - varLine.TrimStart(new char[] { ' ' }).Length <= modsLine.Length - modsLine.TrimStart(new char[] { ' ' }).Length)
                        {
                            break;
                        }
                        // process variables
                        ++_LineCounter; lines.RemoveAt(0);// accept as variable line
                        if (varLine.Trim() == "")
                        {
                            continue;
                        }
                        string[] sv = varLine.Split(new char[] { '=' }, 2);
                        if (varLine.Trim().EndsWith(")"))  // method call
                        {
                            varLine = varLine.Trim();
                            if (build)
                            {
                                await InvokeMethodAsync(varLine, varLine, mod);
                            }
                        }
                        else if (sv.Length >= 2)     // variable assignment
                        {
                            if (build)
                            {
                                AssignVariable(mod, sv[0].Trim(), sv[1].Trim());
                            }
                        }
                        else
                        {
                            throw TemplateError("Variable assignment invalid");
                        }
                    }
                }
                if (build)
                {
                    await page.SaveAsync();
                }
                _CurrentPage = null;
                _CurrentUrl  = null;
            }
        }