* Removes collective_noun and collective_noun_disabled from app * Config Generalization: replaces community_qualified_name with community_name - Generalizes SiteConfig after the removal of collective_noun field - Updates copy where necessary to be readable with community_name - Makes the community_name SiteConfig description more explicit - Adds flexibility for Admins by removing appended "community" * Adds a data_update script to remove collective_noun and collective_noun_disabled * Removes appended community from stories_controller.rb * Removes unnecessary quotation marks around SiteConfig.community_name.to_s * Makes SiteConfig community_name description more explicit * Removes topic from #email_from and replaces arg with _ * Removes argument from #email_from (facepalm) * Reverts changes to application_mailer and notify_mailer_spec * Removes default "Community" topic from application_mailer and makes topic optional * Refactors #prepopulate_new_form to resolve Code Climate failures * Refactors #email_from even further by use of a ternary operator per review suggestion * Simplifies the data_update script used to remove collective_noun per review request * Adds a data_update script to append community to community_name * Updates data_update script to correctly append Community to community_name * Removes RemoveCollectiveNounFromConfig and updates other script * Removes superfluous false from data_update script * Updates data_update script to be more idiomatic
97 lines
2.7 KiB
Ruby
97 lines
2.7 KiB
Ruby
module Admin
|
|
class PagesController < Admin::ApplicationController
|
|
layout "admin"
|
|
|
|
def index
|
|
@pages = Page.all
|
|
@code_of_conduct = Page.find_by(slug: "code-of-conduct")
|
|
@privacy = Page.find_by(slug: "privacy")
|
|
@terms = Page.find_by(slug: "terms")
|
|
end
|
|
|
|
def new
|
|
if params[:slug]
|
|
prepopulate_new_form params[:slug]
|
|
else
|
|
@page = Page.new
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@page = Page.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@page = Page.find(params[:id])
|
|
@page.assign_attributes(page_params)
|
|
if @page.valid?
|
|
@page.update!(page_params)
|
|
redirect_to admin_pages_path
|
|
else
|
|
flash.now[:error] = @page.errors_as_sentence
|
|
render :edit
|
|
end
|
|
end
|
|
|
|
def create
|
|
@page = Page.new(page_params)
|
|
if @page.valid?
|
|
@page.save!
|
|
redirect_to admin_pages_path
|
|
else
|
|
flash.now[:error] = @page.errors_as_sentence
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@page = Page.find(params[:id])
|
|
@page.destroy
|
|
redirect_to "/admin/pages"
|
|
end
|
|
|
|
private
|
|
|
|
def page_params
|
|
allowed_params = %i[title slug body_markdown body_html body_json description template is_top_level_path
|
|
social_image]
|
|
params.require(:page).permit(allowed_params)
|
|
end
|
|
|
|
def prepopulate_new_form(slug)
|
|
html = view_context.render partial: "pages/coc_text",
|
|
locals: {
|
|
community_name: view_context.community_name,
|
|
email_link: view_context.email_link
|
|
}
|
|
@page = case slug
|
|
when "code-of-conduct"
|
|
Page.new(
|
|
slug: params[:slug],
|
|
body_html: html,
|
|
title: "Code of Conduct",
|
|
description: "A page that describes how to behave on this platform",
|
|
is_top_level_path: true,
|
|
)
|
|
when "privacy"
|
|
Page.new(
|
|
slug: params[:slug],
|
|
body_html: html,
|
|
title: "Privacy Policy",
|
|
description: "A page that describes the privacy policy",
|
|
is_top_level_path: true,
|
|
)
|
|
when "terms"
|
|
Page.new(
|
|
slug: params[:slug],
|
|
body_html: html,
|
|
title: "Terms of Use",
|
|
description: "A page that describes the terms of use for the application",
|
|
is_top_level_path: true,
|
|
)
|
|
else
|
|
Page.new
|
|
end
|
|
end
|
|
end
|
|
end
|