From 9a0d2c6a255abed6be8cb8c5bc311e4fba346c05 Mon Sep 17 00:00:00 2001 From: Absurdon Date: Sat, 4 Mar 2017 22:45:05 +0100 Subject: [PATCH] Added creator to ban modell --- app/controllers/bans_controller.rb | 1 + app/models/ban.rb | 4 +++- db/migrate/20170304191254_add_creator_to_bans.rb | 6 ++++++ db/schema.rb | 4 +++- 4 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20170304191254_add_creator_to_bans.rb diff --git a/app/controllers/bans_controller.rb b/app/controllers/bans_controller.rb index 83496c5..c94dd0d 100644 --- a/app/controllers/bans_controller.rb +++ b/app/controllers/bans_controller.rb @@ -20,6 +20,7 @@ class BansController < ApplicationController def create @ban = Ban.new(params[:ban]) raise AccessError unless @ban.can_create? cuser + @ban.creator = cuser if @ban.save flash[:notice] = t(:bans_create) diff --git a/app/models/ban.rb b/app/models/ban.rb index 2d07a1f..936173e 100755 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -13,7 +13,7 @@ # updated_at :datetime # ban_type :integer # ip :string(255) -# +# creator_id :integer class Ban < ActiveRecord::Base include Extra @@ -44,6 +44,8 @@ class Ban < ActiveRecord::Base belongs_to :user belongs_to :server + belongs_to :creator, foreign_key: 'creator_id', class_name: 'User' + def color expiry.past? ? "green" : "red" end diff --git a/db/migrate/20170304191254_add_creator_to_bans.rb b/db/migrate/20170304191254_add_creator_to_bans.rb new file mode 100644 index 0000000..5a09793 --- /dev/null +++ b/db/migrate/20170304191254_add_creator_to_bans.rb @@ -0,0 +1,6 @@ +class AddCreatorToBans < ActiveRecord::Migration + def change + add_column :bans, :creator_id, :integer + add_index :bans, :creator_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 6214a8c..649d7e2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150820223313) do +ActiveRecord::Schema.define(:version => 20170304191254) do create_table "admin_requests", :force => true do |t| t.string "addr" @@ -69,8 +69,10 @@ ActiveRecord::Schema.define(:version => 20150820223313) do t.datetime "updated_at" t.integer "ban_type" t.string "ip" + t.integer "creator_id" end + add_index "bans", ["creator_id"], :name => "index_bans_on_creator_id" add_index "bans", ["server_id"], :name => "index_bans_on_server_id" add_index "bans", ["user_id"], :name => "index_bans_on_user_id"