Added creator to ban modell

This commit is contained in:
Absurdon 2017-03-04 22:45:05 +01:00
parent f3baf7e896
commit 9a0d2c6a25
4 changed files with 13 additions and 2 deletions

View file

@ -20,6 +20,7 @@ class BansController < ApplicationController
def create def create
@ban = Ban.new(params[:ban]) @ban = Ban.new(params[:ban])
raise AccessError unless @ban.can_create? cuser raise AccessError unless @ban.can_create? cuser
@ban.creator = cuser
if @ban.save if @ban.save
flash[:notice] = t(:bans_create) flash[:notice] = t(:bans_create)

View file

@ -13,7 +13,7 @@
# updated_at :datetime # updated_at :datetime
# ban_type :integer # ban_type :integer
# ip :string(255) # ip :string(255)
# # creator_id :integer
class Ban < ActiveRecord::Base class Ban < ActiveRecord::Base
include Extra include Extra
@ -44,6 +44,8 @@ class Ban < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :server belongs_to :server
belongs_to :creator, foreign_key: 'creator_id', class_name: 'User'
def color def color
expiry.past? ? "green" : "red" expiry.past? ? "green" : "red"
end end

View file

@ -0,0 +1,6 @@
class AddCreatorToBans < ActiveRecord::Migration
def change
add_column :bans, :creator_id, :integer
add_index :bans, :creator_id
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # 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| create_table "admin_requests", :force => true do |t|
t.string "addr" t.string "addr"
@ -69,8 +69,10 @@ ActiveRecord::Schema.define(:version => 20150820223313) do
t.datetime "updated_at" t.datetime "updated_at"
t.integer "ban_type" t.integer "ban_type"
t.string "ip" t.string "ip"
t.integer "creator_id"
end 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", ["server_id"], :name => "index_bans_on_server_id"
add_index "bans", ["user_id"], :name => "index_bans_on_user_id" add_index "bans", ["user_id"], :name => "index_bans_on_user_id"