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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 75
def delete
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
63
64
65
66
67
68
69
70
71
72
73
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 63
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
|
# 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
if username.blank?
users = User.order("#{sort} #{dir}").offset(start).limit(limit)
total_count = User.count
else
users = User.where('username like ? or email like ?', "%#{username}%", "%#{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
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
|
# File 'app/controllers/erp_app/desktop/user_management/base_controller.rb', line 26
def new
response = {}
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
|