2009-01-15 12:14:01 +01:00
|
|
|
class MembershipsController < ApplicationController
|
|
|
|
before_filter :authenticate_membership_or_admin
|
2009-01-13 19:01:56 +01:00
|
|
|
|
|
|
|
def add_member
|
|
|
|
user = User.find(params[:user_id])
|
|
|
|
Membership.create(:group => @group, :user => user)
|
2009-02-02 17:28:59 +01:00
|
|
|
redirect_to :action => 'reload', :id => @group
|
2009-01-13 19:01:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def drop_member
|
|
|
|
begin
|
|
|
|
Membership.find(params[:membership_id]).destroy
|
|
|
|
if User.find(@current_user.id).role_admin?
|
2009-02-02 17:28:59 +01:00
|
|
|
redirect_to :action => 'reload', :id => @group
|
2009-01-13 19:01:56 +01:00
|
|
|
else
|
|
|
|
# If the user drops himself from admin group
|
|
|
|
flash[:notice] = MESG_NO_ADMIN_ANYMORE
|
|
|
|
render(:update) {|page| page.redirect_to :controller => "index"}
|
|
|
|
end
|
|
|
|
rescue => error
|
|
|
|
flash[:error] = error.to_s
|
2009-02-02 17:28:59 +01:00
|
|
|
redirect_to :action => 'reload', :id => @group
|
2009-01-13 19:01:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
render :update do |page|
|
2009-01-15 12:14:01 +01:00
|
|
|
page.replace_html 'members', :partial => 'shared/memberships/current_members', :object => @group
|
|
|
|
page.replace_html 'non_members', :partial => 'shared/memberships/non_members', :object => @group
|
2009-01-13 19:01:56 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|