memberships_controller.rb
2.4 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
71
72
73
class MembershipsController < MyProfileController
protect 'manage_memberships', :profile
def index
@roles = environment.roles.select do |role|
ra = profile.role_assignments.find_by_role_id(role.id)
ra.present? && ra.resource_type == 'Profile'
end
@filter = params[:filter_type].to_i
begin
@memberships = @filter.zero? ? profile.memberships : profile.memberships_by_role(environment.roles.find(@filter))
rescue ActiveRecord::RecordNotFound
@memberships = []
end
end
def new_community
@community = Community.new(params[:community])
@community.environment = environment
@back_to = params[:back_to] || url_for(:action => 'index')
if request.post? && @community.valid?
begin
# Community was created
@community = Community.create_after_moderation(user, params[:community].merge({:environment => environment}))
@community.reload
redirect_to :action => 'welcome', :community_id => @community.id, :back_to => @back_to
rescue ActiveRecord::RecordNotFound
# Community pending approval
session[:notice] = _('Your new community creation request will be evaluated by an administrator. You will be notified.')
redirect_to @back_to
end
return
end
end
def welcome
@community = Community.find(params[:community_id])
@back_to = params[:back_to]
end
def suggest
@suggestions = profile.suggested_profiles.of_community.enabled.includes(:suggestion).limit(per_page)
end
def remove_suggestion
@community = profile.suggested_communities.find_by_identifier(params[:id])
custom_per_page = params[:per_page] || per_page
redirect_to :action => 'suggest' unless @community
if @community && request.post?
profile.remove_suggestion(@community)
@suggestions = profile.suggested_profiles.of_community.enabled.includes(:suggestion).limit(custom_per_page)
render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :communities_suggestions, :per_page => custom_per_page}
end
end
def connections
@suggestion = profile.suggested_profiles.of_community.enabled.find_by_suggestion_id(params[:id])
if @suggestion
@tags = @suggestion.tag_connections
@profiles = @suggestion.profile_connections
else
redirect_to :action => 'suggest'
end
end
protected
def per_page
12
end
end