Merge pull request #4833 from nottalulah/master

make appeals editable
This commit is contained in:
evazion
2021-07-10 02:26:36 -05:00
committed by GitHub
4 changed files with 45 additions and 1 deletions

View File

@@ -31,4 +31,17 @@ class PostAppealsController < ApplicationController
fmt.html { redirect_to post_appeals_path(search: { id: @post_appeal.id }) }
end
end
def edit
@post_appeal = authorize PostAppeal.find(params[:id])
respond_with(@post_appeal)
end
def update
@post_appeal = authorize PostAppeal.find(params[:id])
@post_appeal.update(permitted_attributes(@post_appeal))
respond_with(@post_appeal) do |fmt|
fmt.html { redirect_to post_path(@post_appeal.post) }
end
end
end

View File

@@ -1,5 +1,17 @@
class PostAppealPolicy < ApplicationPolicy
def permitted_attributes
def edit?
update?
end
def update?
unbanned? && record.pending? && record.creator_id == user.id
end
def permitted_attributes_for_create
[:post_id, :reason]
end
def permitted_attributes_for_update
[:reason]
end
end

View File

@@ -6,6 +6,10 @@
<span class="prose"><em>no reason</em></span>
<% end %>
<% if policy(appeal).edit? %>
(<%= link_to "edit", edit_post_appeal_url(appeal) %>)
<% end %>
(<%= link_to_user(appeal.creator) %>, <%= time_ago_in_words_tagged(appeal.created_at) %>)
</li>
</ul>

View File

@@ -0,0 +1,15 @@
<div id="c-post-appeals">
<div id="a-edit">
<h1>Edit Appeal</h1>
<p>
Editing appeal for <%= link_to "post ##{@post_appeal.post_id}", @post_appeal.post %>.
</p>
<%= edit_form_for(@post_appeal) do |f| %>
<%= f.input :reason, as: :dtext, inline: true %>
<%= f.button :submit, "Submit" %>
<%= dtext_preview_button "post_appeal_reason" %>
<% end %>
</div>
</div>