diff --git a/app/controllers/post_appeals_controller.rb b/app/controllers/post_appeals_controller.rb index 14d367688..0a8f8cc86 100644 --- a/app/controllers/post_appeals_controller.rb +++ b/app/controllers/post_appeals_controller.rb @@ -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 diff --git a/app/policies/post_appeal_policy.rb b/app/policies/post_appeal_policy.rb index f9f125acb..fa18feaf1 100644 --- a/app/policies/post_appeal_policy.rb +++ b/app/policies/post_appeal_policy.rb @@ -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 diff --git a/app/views/post_appeals/_reasons.html.erb b/app/views/post_appeals/_reasons.html.erb index 9e6fb87a1..675a9b8b4 100644 --- a/app/views/post_appeals/_reasons.html.erb +++ b/app/views/post_appeals/_reasons.html.erb @@ -6,6 +6,10 @@ no reason <% 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) %>) diff --git a/app/views/post_appeals/edit.html.erb b/app/views/post_appeals/edit.html.erb new file mode 100644 index 000000000..a5554fd50 --- /dev/null +++ b/app/views/post_appeals/edit.html.erb @@ -0,0 +1,15 @@ +
+
+

Edit Appeal

+ +

+ Editing appeal for <%= link_to "post ##{@post_appeal.post_id}", @post_appeal.post %>. +

+ + <%= 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 %> +
+