2014-03-23 00:22:25 +00:00
|
|
|
class ServersController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_server, except: [:index, :refresh, :new, :create]
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def index
|
2020-04-02 02:51:37 +00:00
|
|
|
@servers = Server.hlds.active.ordered.includes(:user).all
|
|
|
|
@ns2 = Server.ns2.active.ordered.includes(:user).all
|
2014-03-23 00:22:25 +00:00
|
|
|
@officials = Server.ns2.active.ordered.where ["name LIKE ?", "%NSL%"]
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@server = Server.new
|
|
|
|
raise AccessError unless @server.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @server.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-18 03:38:17 +00:00
|
|
|
@server = Server.new(Server.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
@server.user = cuser
|
|
|
|
raise AccessError unless @server.can_create? cuser
|
|
|
|
|
|
|
|
if @server.save
|
|
|
|
flash[:notice] = t(:server_create)
|
|
|
|
redirect_to @server
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :new
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @server.can_update? cuser
|
|
|
|
|
2020-03-18 03:38:17 +00:00
|
|
|
if @server.update_attributes(Server.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
flash[:notice] = t(:server_update)
|
|
|
|
redirect_to @server
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
raise AccessError unless @server.can_update? cuser
|
|
|
|
@server.default_record
|
2014-03-31 21:33:16 +00:00
|
|
|
render text: 'Ok'
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @server.can_destroy? cuser
|
2014-04-27 02:11:47 +00:00
|
|
|
|
|
|
|
if @server.destroy
|
|
|
|
flash[:notice] = t(:server_destroy)
|
|
|
|
redirect_to servers_url
|
|
|
|
end
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_server
|
|
|
|
@server = Server.find params[:id]
|
|
|
|
end
|
|
|
|
end
|