def test_prepare_wiki_nav(self, app, client): from app.wiki.helpers import prepare_wiki_nav self.login(client, self.admin) self.assertEqual(len(prepare_wiki_nav()), 2) self.login(client, self.moderator) self.assertEqual(len(prepare_wiki_nav()), 3) self.login(client, self.user) self.assertEqual(len(prepare_wiki_nav()), 2) self.login(client, self.user2) self.assertEqual(len(prepare_wiki_nav()), 2)
def view(id, name=None): wikientry = WikiEntry.query.filter_by(id=id).first_or_404() if not wikientry.is_viewable_by_user(): return deny_access(no_perm_url) if not wikientry.is_visible: flash("This article is only visible to you.", "warning") map_nodes = get_nodes_by_wiki_id(id) return render_template("wiki/view.html", entry=wikientry, nav=(prepare_wiki_nav(), WikiSearchForm()), map_nodes=map_nodes, title=page_title(f"View Wiki Article '{wikientry.title}'"))
def edit(id): wikientry = WikiEntry.query.filter_by(id=id).first_or_404() form = WikiEntryForm() form.submit.label.text = "Save Article" cats = gen_category_strings() # TODO: write custom decorators for this? if not current_user.has_admin_role() and current_user.has_wiki_role() and wikientry.is_visible == False and wikientry.created_by.has_admin_role(): flash_no_permission() return redirect(url_for(no_perm_url)) if not current_user.is_wiki_admin() and wikientry.is_visible == False and not wikientry.created_by == current_user: flash_no_permission() return redirect(url_for(no_perm_url)) if not current_user.is_wiki_admin(): del form.is_visible if not current_user.has_admin_role(): del form.dm_content if form.validate_on_submit(): wikientry.title = form.title.data wikientry.content = form.content.data wikientry.category = form.category.data wikientry.tags = form.tags.data if current_user.is_wiki_admin(): wikientry.is_visible = form.is_visible.data if current_user.has_admin_role(): wikientry.dm_content = form.dm_content.data db.session.commit() flash("Wiki entry was edited.", "success") return redirect(url_for("wiki.view", id=id)) elif request.method == "GET": form.title.data = wikientry.title form.content.data = wikientry.content form.category.data = wikientry.category form.tags.data = wikientry.tags if current_user.is_wiki_admin(): form.is_visible.data = wikientry.is_visible if current_user.has_admin_role(): form.dm_content.data = wikientry.dm_content return render_template("wiki/edit.html", form=form, nav=(prepare_wiki_nav(), WikiSearchForm()), cats=cats, entry=wikientry, title=page_title("Edit Wiki Article '%s'" % wikientry.title))
def view(id): wikientry = WikiEntry.query.filter_by(id=id).first_or_404() # TODO: write custom decorator / function for this? if not current_user.is_wiki_admin() and wikientry.is_visible == False and not wikientry.created_by == current_user: flash_no_permission() return redirect(url_for(no_perm_url)) if not current_user.has_admin_role() and current_user.has_wiki_role() and wikientry.is_visible == False and wikientry.created_by.has_admin_role(): flash_no_permission() return redirect(url_for(no_perm_url)) map_nodes = get_nodes_by_wiki_id(id) return render_template("wiki/view.html", entry=wikientry, nav=(prepare_wiki_nav(), WikiSearchForm()), map_nodes=map_nodes, title=page_title("View Wiki Article '%s'" % wikientry.title))
def edit(id, name=None): wikientry = WikiEntry.query.filter_by(id=id).first_or_404() if not wikientry.is_editable_by_user(): return deny_access(no_perm_url) form = WikiEntryForm() form.submit.label.text = "Save Article" cats = gen_category_strings() if wikientry.id == 1: del form.title if not wikientry.is_hideable_by_user(): del form.is_visible if form.validate_on_submit(): if wikientry.id != 1: wikientry.title = form.title.data wikientry.content = form.content.data wikientry.category = form.category.data wikientry.tags = form.tags.data if wikientry.is_hideable_by_user(): wikientry.is_visible = form.is_visible.data db.session.commit() flash("Wiki entry was edited.", "success") return redirect(wikientry.view_url()) elif request.method == "GET": if wikientry.id != 1: form.title.data = wikientry.title form.content.data = wikientry.content form.category.data = wikientry.category form.tags.data = wikientry.tags if wikientry.is_hideable_by_user(): form.is_visible.data = wikientry.is_visible return render_template("wiki/edit.html", form=form, nav=(prepare_wiki_nav(), WikiSearchForm()), cats=cats, entry=wikientry, title=page_title(f"Edit Wiki Article '{wikientry.title}'"))
def create(): form = WikiEntryForm() form.submit.label.text = "Create Article" cats = gen_category_strings() if form.validate_on_submit(): entry = WikiEntry(title=form.title.data, content=form.content.data, category=form.category.data, tags=form.tags.data, is_visible=form.is_visible.data) db.session.add(entry) db.session.commit() flash("Wiki entry was added.", "success") return redirect(entry.view_url()) elif request.method == "GET": form.is_visible.data = True return render_template("wiki/create.html", form=form, nav=(prepare_wiki_nav(), WikiSearchForm()), cats=cats, title=page_title("Add Wiki Article"))
def create(): form = WikiEntryForm() form.submit.label.text = "Create Article" cats = gen_category_strings() if not current_user.is_wiki_admin(): del form.is_visible if not current_user.has_admin_role(): del form.dm_content if form.validate_on_submit(): if current_user.is_wiki_admin(): visible = form.is_visible.data else: ws = WikiSetting.query.get(1) visible = ws.default_visible dm_content = "" if current_user.has_admin_role(): dm_content = form.dm_content.data entry = WikiEntry(title=form.title.data, content=form.content.data, category=form.category.data, tags=form.tags.data, is_visible=visible, dm_content=dm_content) db.session.add(entry) db.session.commit() flash("Wiki entry was added.", "success") return redirect(url_for("wiki.view", id=entry.id)) elif request.method == "GET": if current_user.is_wiki_admin(): wsettings = WikiSetting.query.get(1) form.is_visible.data = wsettings.default_visible return render_template("wiki/create.html", form=form, nav=(prepare_wiki_nav(), WikiSearchForm()), cats=cats, title=page_title("Add Wiki Article"))
def recent(): created = get_recently_created() edited = get_recently_edited() return render_template("wiki/recent.html", nav=(prepare_wiki_nav(), WikiSearchForm()), created=created, edited=edited, title=page_title("Recent changes"))
def search_tag(tag): results = search_wiki_tag(tag) return render_template("wiki/search_tag.html", nav=(prepare_wiki_nav(), WikiSearchForm()), results=results, tag=tag, title=page_title("Search for Tag '%s'" % tag))
def search_text(text): results = search_wiki_text(text) results = prepare_search_result(text, results) return render_template("wiki/search_text.html", nav=(prepare_wiki_nav(), WikiSearchForm()), results=results, term=text, title=page_title("Search for '%s'" % text))