link tags from modlog

This commit is contained in:
Peter Bhat Harkins 2018-04-11 08:18:02 -05:00
parent 2105656d8f
commit 93fe0fdd74
7 changed files with 17 additions and 5 deletions

View File

@ -123,4 +123,4 @@ in a `config/initializers/production.rb` or similar file:
#### Administration
Basic moderation happens on-site, but most other administrative tasks require use of the rails console in production.
Side administrators can create and edit tags at `/tags`.
Administrators can create and edit tags at `/tags`.

View File

@ -3,8 +3,9 @@ class Moderation < ApplicationRecord
:class_name => "User",
:foreign_key => "moderator_user_id",
:inverse_of => :moderations
belongs_to :story
belongs_to :comment
belongs_to :story
belongs_to :tag
belongs_to :user
after_create :send_message_to_moderated

View File

@ -60,6 +60,7 @@ class Tag < ApplicationRecord
self.changes.map {|f, c| "changed #{f} from '#{c[0]}' to '#{c[1]}'" } .join(', ')
end
m.moderator_user_id = @edit_user_id
m.tag = self
end
end
end

View File

@ -38,6 +38,8 @@
<%= mod.comment.user.username %>
on
<%= mod.comment.story.title %></a>
<% elsif mod.tag %>
<%= link_to("Tag: #{mod.tag.tag}", mod.tag) %>
<% elsif mod.user_id %>
<% if mod.user %>
<a href="/u/<%= mod.user.username %>">User

View File

@ -0,0 +1,5 @@
class TagModerationLog < ActiveRecord::Migration[5.1]
def change
add_column :moderations, :tag_id, :integer, null: true, default: nil
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180201184612) do
ActiveRecord::Schema.define(version: 20180411131217) do
create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.datetime "created_at", null: false
@ -112,6 +112,7 @@ ActiveRecord::Schema.define(version: 20180201184612) do
t.text "action", limit: 16777215
t.text "reason", limit: 16777215
t.boolean "is_from_suggestions", default: false
t.integer "tag_id"
t.index ["created_at"], name: "index_moderations_on_created_at"
end

View File

@ -39,9 +39,11 @@ describe TagsController do
expect(tag.inactive).to be true
end
it 'creates a moderation with the expected user_id' do
it 'creates a moderation with the expected tag_id and user_id' do
post :create, params: { tag: { tag: 'mytag' } }
expect(Moderation.order(id: :desc).first.moderator_user_id).to eq user_id
mod = Moderation.order(id: :desc).first
expect(mod.tag_id).to eq Tag.order(id: :desc).first.id
expect(mod.moderator_user_id).to eq user_id
end
end