Class: ErpApp::Desktop::UserManagement::BaseController
- Inherits:
-
BaseController
show all
- Defined in:
- app/controllers/erp_app/desktop/user_management/base_controller.rb
Instance Method Summary
collapse
Instance Method Details
#delete ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 77
def delete
application = DesktopApplication.find_by_internal_identifier('user_management')
if current_user.has_capability?('create', 'User')
unless @user.party.nil?
@user.party.destroy
else
@user.destroy
end
render :json => {:success => true}
else
render :json => {:success => false, :message => 'Invalid Access'}
end
end
|
#get_details ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 65
def get_details
if @user.party.business_party.is_a?(Individual)
business_party = @user.party.business_party.to_json(:only => [:current_first_name, :current_last_name, :gender, :total_years_work_experience])
else
business_party = @user.party.business_party.to_json(:only => [:description])
end
render :inline => "{entityType:'#{@user.party.business_party.class.to_s}',
businessParty:#{business_party},
userInfo:#{@user.to_json(:only => [:username, :email, :last_login_at, :last_activity_at, :failed_logins_count, :activation_state])}}"
end
|
#index ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 7
def index
username = params[:username]
sort_hash = params[:sort].blank? ? {} : Hash.symbolize_keys(JSON.parse(params[:sort]).first)
sort = sort_hash[:property] || 'username'
dir = sort_hash[:direction] || 'ASC'
limit = params[:limit] || 25
start = params[:start] || 0
total_count = 0
if username.blank?
users = User.order("#{sort} #{dir}").offset(start).limit(limit)
total_count = User.count
else
users = User.where('username like ?', "%#{username}%").order("#{sort} #{dir}").offset(start).limit(limit)
total_count = users.count
end
render :inline => "{\"totalCount\":#{total_count},data:#{users.to_json(:only => [:id, :username, :email, :party_id])}}"
end
|
#new ⇒ Object
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
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 27
def new
response = {}
application = DesktopApplication.find_by_internal_identifier('user_management')
begin
current_user.with_capability(:create, 'User') do
user = User.new(
:email => params[:email],
:username => params[:username],
:password => params[:password],
:password_confirmation => params[:password_confirmation]
)
user.add_instance_attribute(:login_url, '/erp_app/login');
user.add_instance_attribute(:temp_password, params[:password]);
if user.save
individual = Individual.create(:gender => params[:gender], :current_first_name => params[:first_name], :current_last_name => params[:last_name])
user.party = individual.party
user.save
response = {:success => true}
else
message = "<ul>"
user.errors.collect do |e, m|
message << "<li>#{e} #{m}</li>"
end
message << "</ul>"
response = {:success => false, :message => message}
end
render :json => response
end
rescue ErpTechSvcs::Utils::CompassAccessNegotiator::Errors::UserDoesNotHaveCapability=>ex
render :json => {:success => false, :message => ex.message}
end
end
|