Merge branch 'master' into master2

This commit is contained in:
edshot99 2024-11-04 12:10:49 -06:00
commit 7d2892da2c
4 changed files with 29 additions and 20 deletions

View File

@ -3,8 +3,7 @@
class HelpController < ApplicationController class HelpController < ApplicationController
respond_to :html, :json respond_to :html, :json
helper :wiki_pages helper :wiki_pages
before_action :admin_only, only: [:new, :create, :edit, before_action :admin_only, except: %i[index show]
:update, :destroy]
def show def show
if params[:id] =~ /\A\d+\Z/ if params[:id] =~ /\A\d+\Z/
@ -18,16 +17,14 @@ class HelpController < ApplicationController
redirect_to help_pages_path redirect_to help_pages_path
end end
end end
format.json do
raise ActiveRecord::RecordNotFound if @help.blank?
render json: @help
end
end end
end end
def index def index
@help_pages = HelpPage.help_index @help_pages = HelpPage.help_index
respond_with(@help_pages) respond_with(@help_pages) do |format|
format.json { render json: @help_pages.to_json }
end
end end
def new def new
@ -42,27 +39,20 @@ class HelpController < ApplicationController
def create def create
@help = HelpPage.create(help_params) @help = HelpPage.create(help_params)
if @help.valid? flash[:notice] = "Help page created" if @help.valid?
flash[:notice] = 'Help page created'
ModAction.log(:help_create, {name: @help.name, wiki_page: @help.wiki_page})
end
respond_with(@help) respond_with(@help)
end end
def update def update
@help = HelpPage.find(params[:id]) @help = HelpPage.find(params[:id])
@help.update(help_params) @help.update(help_params)
if @help.valid? flash[:notice] = "Help entry updated" if @help.valid?
flash[:notice] = "Help entry updated"
ModAction.log(:help_update,{name: @help.name, wiki_page: @help.wiki_page})
end
respond_with(@help) respond_with(@help)
end end
def destroy def destroy
@help = HelpPage.find(params[:id]) @help = HelpPage.find(params[:id])
@help.destroy @help.destroy
ModAction.log(:help_delete, {name: @help.name, wiki_page: @help.wiki_page})
respond_with(@help) respond_with(@help)
end end

View File

@ -98,7 +98,7 @@ FilterUtils.normalizeData = (value, type) => {
case "width": case "width":
case "height": case "height":
case "score": case "score":
case "favcout": case "favcount":
case "userid": case "userid":
return parseInt(value); return parseInt(value);
case "rating": case "rating":

View File

@ -160,10 +160,10 @@ div#c-users {
grid-area: p-posts; grid-area: p-posts;
display: flex; display: flex;
overflow: auto; overflow: auto;
justify-content: space-between; justify-content: flex-start;
flex-wrap: wrap; flex-wrap: wrap;
gap: 0.5em; gap: 1em;
padding: 0.5em; padding: 0.5em;
background: var(--color-section); background: var(--color-section);
@ -176,7 +176,7 @@ div#c-users {
} }
article.post-preview { article.post-preview {
flex: 0 0 150px; flex: 0 0 154px;
margin: 0; margin: 0;
img { max-width: unset !important; } img { max-width: unset !important; }
} }

View File

@ -5,7 +5,10 @@ class HelpPage < ApplicationRecord
validates :wiki_page, :name, presence: true validates :wiki_page, :name, presence: true
normalizes :name, with: ->(name) { name.downcase.strip.tr(" ", "_") } normalizes :name, with: ->(name) { name.downcase.strip.tr(" ", "_") }
validate :wiki_page_exists validate :wiki_page_exists
after_create :log_create
after_update :log_update
after_destroy :invalidate_cache after_destroy :invalidate_cache
after_destroy :log_destroy
after_save :invalidate_cache after_save :invalidate_cache
belongs_to :wiki, class_name: "WikiPage", foreign_key: "wiki_page", primary_key: "title" belongs_to :wiki, class_name: "WikiPage", foreign_key: "wiki_page", primary_key: "title"
@ -37,4 +40,20 @@ class HelpPage < ApplicationRecord
def self.help_index def self.help_index
Cache.fetch("help_index", expires_in: 12.hours) { HelpPage.all.sort_by(&:pretty_title) } Cache.fetch("help_index", expires_in: 12.hours) { HelpPage.all.sort_by(&:pretty_title) }
end end
module LogMethods
def log_create
ModAction.log(:help_create, { name: name, wiki_page: wiki_page })
end
def log_update
ModAction.log(:help_update, { name: name, wiki_page: wiki_page })
end
def log_destroy
ModAction.log(:help_delete, { name: name, wiki_page: wiki_page })
end
end
include LogMethods
end end