organizations_controller.rb
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
62
63
64
65
66
67
68
69
70
class OrganizationsController < AdminController
protect 'manage_environment_organizations', :environment
def index
@filter = params[:filter] || 'any'
@title = _('Organization profiles')
@type = params[:type] || "any"
@types_filter = [[_('All'), 'any'], [_('Community'), 'Community'], [_('Enterprise'), 'Enterprise']]
@plugins.dispatch_without_flatten(:organization_types_filter_options).each do |plugin_response|
@types_filter = @types_filter | plugin_response
end
@types_hash = {}
@types_filter.each{|list| @types_hash[list.last] = list.first}
scope = @plugins.dispatch_first(:filter_manage_organization_scope, @type)
if scope.blank?
scope = environment.organizations
scope = scope.where(:type => @type) if @type != 'any'
end
if @filter == 'enabled'
scope = scope.visible
elsif @filter == 'disabled'
scope = scope.disabled
end
scope = scope.order('name ASC')
@q = params[:q]
@collection = find_by_contents(:organizations, environment, scope, @q, {:per_page => per_page, :page => params[:npage]})[:results]
end
def activate
organization = environment.organizations.find(params[:id])
if organization.enable
render :text => (_('%s enabled') % organization.name).to_json
else
render :text => (_('%s could not be enabled') % organization.name).to_json
end
end
def deactivate
organization = environment.organizations.find(params[:id])
if organization.disable
render :text => (_('%s disabled') % organization.name).to_json
else
render :text => (_('%s could not be disable') % organization.name).to_json
end
end
def destroy
if request.post?
organization = environment.organizations.find(params[:id])
if organization && organization.destroy
render :text => (_('%s removed') % organization.name).to_json
else
render :text => (_('%s could not be removed') % organization.name).to_json
end
else
render :nothing => true
end
end
private
def per_page
10
end
end