Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed group edit redirects and added ability to add any user to gro…

…up - closes #237 and closes #267
  • Loading branch information...
commit 1c35569375ad124e6703d2780f335feb0e7c3423 1 parent 3149360
@augustf augustf authored
View
10 app/controllers/memberships_controller.rb
@@ -18,7 +18,7 @@ def create
respond_to do |format|
if @membership.save
- format.html { redirect_to(@group, :notice => t(:membership_created)) }
+ format.html { redirect_to({:controller => :groups, :action => :edit, :id => @group}, :notice => t(:membership_created)) }
format.xml { render :xml => @group, :status => :created, :location => @group }
else
format.html { redirect_to @group }
@@ -34,7 +34,7 @@ def update
respond_to do |format|
if (@membership.can_resign_leadership?) && (@membership.update_attributes(params[:membership]))
- format.html { redirect_to(@group, :notice => t(:membership_updated)) }
+ format.html { redirect_to({:controller => :groups, :action => :edit, :id => @group}, :notice => t(:membership_updated)) }
format.xml { head :ok }
else
format.html { redirect_to @group , :notice => @group.errors}
@@ -50,7 +50,7 @@ def destroy
respond_to do |format|
if (@membership.can_resign_leadership?) && (@membership.destroy)
- format.html { redirect_to(@group, :notice => t(:member_removed)) }
+ format.html { redirect_to({:controller => :groups, :action => :edit, :id => @group}, :notice => t(:member_removed)) }
format.xml { head :ok }
else
format.html { redirect_to @group, :notice => t(:membership_denied) }
@@ -64,9 +64,9 @@ def approve
membership = Membership.find(params[:id])
respond_to do |format|
if membership.approve()
- format.html { redirect_to(group_path(params[:group_id]), :notice => t(:membership_approved)) }
+ format.html { redirect_to(edit_group_path(params[:group_id]), :notice => t(:membership_approved)) }
else
- format.html { redirect_to(group_path(params[:group_id]), :notice => t(:membership_denied)) }
+ format.html { redirect_to(edit_group_path(params[:group_id]), :notice => t(:membership_denied)) }
end
end
end
View
10 app/models/group.rb
@@ -24,6 +24,16 @@ def update_membership_perms
end
end
+ #Deliver a list of only users not currently in the group
+ #Used for adding new users to a group and avoiding duplication
+ def users_not_in_group
+ users = User.all
+ self.memberships.each do |m|
+ users.delete_if {|key,value| key.id == m.user_id}
+ end
+ return users
+ end
+
# Test if a user is part of this group
def has_member?(user)
users.include?(user)
View
10 app/views/groups/_edit_memberships.html.erb
@@ -91,6 +91,16 @@
</div>
<% end %>
+<% users_not_in_group = @group.users_not_in_group %>
+<% unless users_not_in_group.empty? %>
+ <h3 class="default-padding">Add Users to Group</h3>
+ <%= form_for([@group, Membership.new]) do |f| %>
+ <%= f.label :name %><br />
+ <%= f.collection_select(:user_id, users_not_in_group, :id, :name) %>
+ <%= hidden_field_tag 'autoconfirm' %>
+ <%= f.submit "Add Member", :class => "btn primary" %>
+ <% end %>
+<% end %>
<h3 class="default-padding">Group Leaders</h3>

2 comments on commit 1c35569

@mikldt
Owner

This commit is causing two tests to fail:

test_should_autoaprove_members_added_by_admins(MembershipsControllerTest)
test_should_create_pending_membership(MembershipsControllerTest)

The tests seem not to expect to be redirected to /edit.

@augustf
Owner

Yeah - that fix is per Kenley's point at #267 . But we can adjust the tests the suit.

Please sign in to comment.
Something went wrong with that request. Please try again.