diff options
author | Logan Fick <logaldeveloper@protonmail.com> | 2019-02-24 13:01:53 -0500 |
---|---|---|
committer | Logan Fick <logaldeveloper@protonmail.com> | 2019-02-24 13:01:53 -0500 |
commit | 32e7b99b6da9bc5397e65dc4d2a146d7d2da510f (patch) | |
tree | 52a5aa2f203653d6dbe573cb1ede477a12fc8100 | |
parent | 244a047cad85690a29af12c2f3d7866fe9f79e40 (diff) | |
parent | 2fe1cead68d3f66be5a9c6003990362e99bc1307 (diff) |
Merged pull request #56.
-rw-r--r-- | app/controllers/forums_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/forumthreads_controller.rb | 3 | ||||
-rw-r--r-- | app/views/forums/edit.html.erb | 4 | ||||
-rw-r--r-- | app/views/forums/new.html.erb | 4 | ||||
-rw-r--r-- | app/views/forumthreads/edit.html.erb | 6 | ||||
-rw-r--r-- | db/migrate/20190224093907_disable_deletion_forums.rb | 5 | ||||
-rw-r--r-- | db/schema.rb | 15 | ||||
-rw-r--r-- | db/seeds.rb | 2 |
8 files changed, 30 insertions, 11 deletions
diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 206f01f..16ea5b2 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -89,7 +89,7 @@ class ForumsController < ApplicationController end def forum_params(add = []) - a = [:name, :position, :role_read_id, :role_write_id, :necro_length] + add + a = [:name, :position, :role_read_id, :role_write_id, :necro_length, :disable_deletion] + add params.require(:forum).permit(a) end end diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index d40ce58..4a3a5c1 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -10,6 +10,7 @@ class ForumthreadsController < ApplicationController @threads = Forumthread.filter(current_user, params[:title].try(:slice, 0..255), params[:content].try(:slice, 0..255), params[:reply].try(:slice, 0..255), params[:label], User.find_by(ign: params[:author].to_s.strip) || params[:author], params[:query].try(:slice, 0..255), Forum.find_by(id: params[:forum])) .page(params[:page]).per(30) end + def show if params[:reverse] == "true" @replies = @thread.replies.order(id: :desc).page(params[:page]) @@ -72,7 +73,7 @@ class ForumthreadsController < ApplicationController end def destroy - if mod? || @thread.author.is?(current_user) + if mod? || (@thread.author.is?(current_user) && !@thread.forum.disable_deletion) if @thread.destroy flash[:notice] = "Thread deleted!" else diff --git a/app/views/forums/edit.html.erb b/app/views/forums/edit.html.erb index b1a5a2e..bb4a853 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -25,6 +25,10 @@ <td><%= f.label :necro_length, "Necropost warning delay (in days)" %></td> <td><%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %></td> </tr> + <tr> + <td><%= f.label :disable_deletion, "Disable deletion of threads for non-staff" %></td> + <td><%= f.check_box :disable_deletion %></td> + </tr> </table> <p><%= f.submit "Update Forum", class: "btn blue left" %></p> <% end %> diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index 3640fd7..02eacaf 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -25,6 +25,10 @@ <td><%= f.label :necro_length, "Necropost warning delay (in days)" %></td> <td><%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %></td> </tr> + <tr> + <td><%= f.label :disable_deletion %></td> + <td><%= f.check_box :disable_deletion %></td> + </tr> </table> <%= f.hidden_field :forumgroup_id %> <p><%= f.submit "Create Forum", class: "btn blue left" %></p> diff --git a/app/views/forumthreads/edit.html.erb b/app/views/forumthreads/edit.html.erb index 5667cf2..30c9b08 100644 --- a/app/views/forumthreads/edit.html.erb +++ b/app/views/forumthreads/edit.html.erb @@ -11,6 +11,8 @@ end %> +<% forum = Forum.find(@thread.forum_id) %> + <h1>Edit Thread</h1> <%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → <%= link_to @thread, @thread %> → Edit thread <%= form_for @thread do |f|%> @@ -37,5 +39,7 @@ <%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content} %> <p><%= f.submit "Update Thread", class: "btn blue left" %></p> <% end %> -<%= button_to "Delete Thread", @thread, :method => "delete", data: {confirm: "Delete thread & comments forever?"}, class: "btn red right" %> +<% if mod? || !forum.disable_deletion %> + <%= button_to "Delete Thread", @thread, :method => "delete", data: {confirm: "Delete thread & comments forever?"}, class: "btn red right" %> +<% end %> <div class="clear"></div> diff --git a/db/migrate/20190224093907_disable_deletion_forums.rb b/db/migrate/20190224093907_disable_deletion_forums.rb new file mode 100644 index 0000000..d0d0fbe --- /dev/null +++ b/db/migrate/20190224093907_disable_deletion_forums.rb @@ -0,0 +1,5 @@ +class DisableDeletionForums < ActiveRecord::Migration + def change + add_column :forums, :disable_deletion, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index dba9247..aae5789 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190222152638) do +ActiveRecord::Schema.define(version: 20190224093907) do create_table "badges", force: :cascade do |t| t.string "name", limit: 191 @@ -46,12 +46,13 @@ ActiveRecord::Schema.define(version: 20190222152638) do end create_table "forums", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "position", limit: 4 - t.integer "role_read_id", limit: 4 - t.integer "role_write_id", limit: 4 - t.integer "forumgroup_id", limit: 4 - t.integer "necro_length", limit: 4 + t.string "name", limit: 255 + t.integer "position", limit: 4 + t.integer "role_read_id", limit: 4 + t.integer "role_write_id", limit: 4 + t.integer "forumgroup_id", limit: 4 + t.integer "necro_length", limit: 4 + t.boolean "disable_deletion", default: false end create_table "forumthreads", force: :cascade do |t| diff --git a/db/seeds.rb b/db/seeds.rb index 7ecb6de..25dbfed 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -32,7 +32,7 @@ deleted_user = User.create!( password_confirmation: userpw, role: Role.get(:disabled), badge: Badge.get(:none), - discord: "echo123", + discord: "echo123#9804", last_ip: "0.0.0.0", confirmed: true, last_seen: Time.utc(0).to_datetime, |