Class: AdminUsersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin_users_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#after_sign_in_path_for, #any_admin_user_exists?, #first_admin_user_action?

Instance Method Details

#createObject

JSON or HTML



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/admin_users_controller.rb', line 12

def create # JSON or HTML
  @admin = AdminUser.new(params[:admin_user])
  if @admin.save
    respond_to do |format|
      format.json { render :json => {:id => @admin.id} }
      format.html {
        flash[:success] = t('first_admin_user_success')
        #respond_with @admin, :location => domains_path
        (@admin, :bypass => true)
        redirect_to domains_path
      }
    end
  else
    respond_to do |format|
      format.json { render :json => {:errors => @admin.errors } }
      format.html {
        flash[:error] = t('first_admin_user_error')
        render :action => 'first'
      }
    end
  end
end

#destroyObject

JSON only



51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/admin_users_controller.rb', line 51

def destroy # JSON only
  if current_admin_user.super
    AdminUser.find(params[:id]).destroy
    render :json => {:id => nil}
  else
    render :status => 405
  end
rescue
  render :status => 404
end

#firstObject



8
9
10
# File 'app/controllers/admin_users_controller.rb', line 8

def first
  @admin = AdminUser.new
end

#indexObject



3
4
5
# File 'app/controllers/admin_users_controller.rb', line 3

def index
  @admins = AdminUser.includes(:virtual_domains)
end

#updateObject

JSON only



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin_users_controller.rb', line 35

def update # JSON only
  @admin = AdminUser.find(params[:id])
  if  @admin == current_admin_user or current_admin_user.super
    if @admin.change_data params
      render :json => {:id => @admin.id}
    else
      render :json => {:errors => @admin.errors}
    end
  else
    render :json => {:errors => t('not_authorized')}
  end
rescue
  render :json => {:errors => t('unknown_error')}
end