This repository has been archived by the owner on Mar 5, 2020. It is now read-only.
/
domains_controller.rb
executable file
·96 lines (79 loc) · 2.7 KB
/
domains_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class DomainsController < ApplicationController
require_role [ "admin", "owner" ], :unless => "token_user?"
# Keep token users in line
before_filter :restrict_token_movements, :except => :show
def index
@domains = Domain.paginate :page => params[:page], :user => current_user, :order => 'name'
end
def show
if current_user
@domain = Domain.find( params[:id], :user => current_user, :include => :records )
@users = User.active_owners if current_user.admin?
else
@domain = Domain.find( current_token.domain_id, :include => :records )
end
@record = @domain.records.new
end
def new
@domain = Domain.new
@zone_templates = ZoneTemplate.find( :all, :require_soa => true, :user => current_user )
end
def create
@zone_template = ZoneTemplate.find(params[:domain][:zone_template_id]) unless params[:domain][:zone_template_id].blank?
@zone_template ||= ZoneTemplate.find_by_name(params[:domain][:zone_template_name]) unless params[:domain][:zone_template_name].blank?
@domain = Domain.new( params[:domain] )
unless @zone_template.nil?
begin
@domain = @zone_template.build( params[:domain][:name] )
rescue ActiveRecord::RecordInvalid => e
@domain.attach_errors(e)
end
end
@domain.user = current_user unless current_user.has_role?( 'admin' )
respond_to do |format|
if @domain.errors.empty? && @domain.save
format.html {
flash[:info] = "Domain created"
redirect_to domain_path( @domain )
}
format.xml { render :xml => @domain, :status => :created, :location => domain_url( @domain ) }
else
format.html {
@zone_templates = ZoneTemplate.find( :all )
render :action => :new
}
format.xml { render :xml => @domain.errors, :status => :unprocessable_entity }
end
end
end
def edit
@domain = Domain.find( params[:id] )
end
def update
@domain = Domain.find( params[:id] )
if @domain.update_attributes( params[:domain] )
flash[:info] = "Domain was updated!"
redirect_to domain_path(@domain)
else
render :action => 'edit'
end
end
def destroy
@domain = Domain.find( params[:id] )
@domain.destroy
redirect_to :action => 'index'
end
# Non-CRUD methods
def update_note
@domain = Domain.find( params[:id] )
@domain.update_attribute( :notes, params[:domain][:notes] )
end
def change_owner
@domain = Domain.find( params[:id] )
@domain.update_attribute :user_id, params[:domain][:user_id]
end
private
def restrict_token_movements
redirect_to domain_path( current_token.domain ) if current_token
end
end