Class: Users

Inherits:
Application show all
Defined in:
app/controllers/users.rb

Instance Method Summary collapse

Methods inherited from Application

#access_denied, #admin_or_requesting_node, #authenticate_every, #display, #get_available_recipes, #is_admin, #is_admin_or_validator, #redirect_back_or_default, #store_location

Instance Method Details

#createObject

POST to /users



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/users.rb', line 56

def create
  @user = params["inflated_object"]
  begin
    Chef::WebUIUser.cdb_load(@user.name)
  rescue Chef::Exceptions::CouchDBNotFound
    @user.cdb_save
    self.status = 201
  else
    raise Conflict, "User already exists"
  end
  display({ :uri => absolute_url(:user, @user.name) })
end

#destroyObject



69
70
71
72
73
74
75
76
77
# File 'app/controllers/users.rb', line 69

def destroy
  begin
    @user = Chef::WebUIUser.cdb_load(params[:id])
  rescue Chef::Exceptions::CouchDBNotFound => e
    raise NotFound, "Cannot load user #{params[:id]}"
  end
  @user.cdb_destroy
  display @user
end

#indexObject

GET to /users



28
29
30
31
# File 'app/controllers/users.rb', line 28

def index
  @user_list = Chef::WebUIUser.cdb_list
  display(@user_list.inject({}) { |r,n| r[n] = absolute_url(:user, n); r })
end

#showObject

GET to /users/:id



34
35
36
37
38
39
40
41
# File 'app/controllers/users.rb', line 34

def show
  begin
    @user = Chef::WebUIUser.cdb_load(params[:id])
  rescue Chef::Exceptions::CouchDBNotFound => e
    raise NotFound, "Cannot load user #{params[:id]}"
  end
  display @user
end

#updateObject

PUT to /users/:id



44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/users.rb', line 44

def update
  begin
    Chef::WebUIUser.cdb_load(params[:id])
  rescue Chef::Exceptions::CouchDBNotFound => e
    raise NotFound, "Cannot load user #{params[:id]}"
  end
  @user = params['inflated_object']
  @user.cdb_save
  display(@user)
end