Module Dsadmin::Webfe::VhostsControllerCommon
In: lib/dsadmin/webfe/vhosts_controller_common.rb

Methods

create   destroy   edit   index   list   modelname   new   send_rebuild_request   show   sort   trigger_rebuild   update  

Included Modules

Dsadmin::Contractor Dsadmin::CoreClient

Public Instance methods

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 47
47:   def create
48:     @vhost = modelclass.new(params[:vhost])
49:     if @vhost.save
50:       flash[:notice] = "#{modelname} VirtualHost '#{@vhost.hostname}' was successfully created."
51:       send_rebuild_request
52:       redirect_to :action => 'list'
53:     else
54:       render :action => 'new'
55:     end
56:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 73
73:   def destroy
74:     unless(request.post?)
75:       log.error("POST-only action ('destroy') accessed via non-POST")
76:       flash[:error] = "Nah, naughty boy, don't do that!"
77:       redirect_to :action => 'list'
78:       return
79:     end
80:     
81:     vhost = modelclass.find(params[:id])
82:     name = vhost.hostname
83:     vhost.destroy
84:     flash[:notice] = "#{modelname} VirtualHost \"#{name}\" has been destroyed."
85:     send_rebuild_request
86:     redirect_to :action => 'list'
87:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 58
58:   def edit
59:     @vhost = modelclass.find(params[:id])
60:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 29
29:   def index
30:     list
31:     render :action => 'list'
32:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 34
34:   def list
35:     @sortby = params[:sortby] || "hostname"
36:     @vhosts = sort(modelclass.find_overview)
37:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 43
43:   def new
44:     @vhost = modelclass.new
45:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 39
39:   def show
40:     @vhost = modelclass.find(params[:id])
41:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 90
90:   def trigger_rebuild
91:     send_rebuild_request
92: 
93:     redirect_to :action => 'list'
94:   end

[Source]

    # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 62
62:   def update
63:     @vhost = modelclass.find(params[:id])
64:     if @vhost.update_attributes(params[:vhost])
65:       flash[:notice] = "#{modelname} VirtualHost '#{@vhost.hostname}' was successfully updated."
66:       send_rebuild_request
67:       redirect_to :action => 'list'
68:     else
69:       render :action => 'edit'
70:     end
71:   end

Protected Instance methods

[Source]

     # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 100
100:   def modelname
101:     modelclass.name.match(/^(\w+)Vhost$/)[1]
102:   end

[Source]

     # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 105
105:   def send_rebuild_request
106:     proxy = Dsadmin::Webfe::BackendInterface.new
107:     username = Thread.current[:auth_username]
108:     passwd   = Thread.current[:auth_passwd]
109:     
110:     begin
111:       res = proxy.call(:web, :rebuild_vhosts, username, passwd)
112:       
113:       if(res.status == :success)
114:         flash[:notice] = "Success"
115:       else
116:         msg = "Unexpected response on /web/rebuild_vhosts: #{res.status}"
117:         flash[:warning] = msg
118:         log.error(msg)
119:       end
120:     rescue StandardError => e
121:       log.bug(e)
122:       flash[:error] = "Uhh, something went very wrong here. Please kick the admin."
123:     end
124:   end

including controllers have to implement the "sortfields" method (returning an array of field names)!

[Source]

     # File lib/dsadmin/webfe/vhosts_controller_common.rb, line 128
128:   def sort(list)
129:     assertTrue(sortfields.include?(@sortby))
130:     
131:     return list.sort_by { |item| item.send(@sortby) }
132:   end

[Validate]