Skip to content

Commit

Permalink
Reassigning tasks after someone leaves the team, also not allowing th…
Browse files Browse the repository at this point in the history
…e team owner to leave the team, as per lighthouse ticket 18.
  • Loading branch information
Aimee Daniells committed Apr 18, 2009
1 parent dfb30ea commit 7b5fe53
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 75 deletions.
24 changes: 22 additions & 2 deletions app/controllers/memberships_controller.rb
Expand Up @@ -4,6 +4,7 @@ class MembershipsController < ApplicationController
before_filter :find_membership, :only => [:accept, :destroy]
before_filter :edit_access_required, :only => [:accept]
before_filter :delete_access_required, :only => [:destroy]
before_filter :delete_access_required_to_leave, :only => [:leave]

def new
@invitee = Person.find(params[:person_id])
Expand Down Expand Up @@ -50,6 +51,17 @@ def destroy
redirect_back
end

def leave
Task.assigned_to_person_in_team(@membership.person, @membership.team).each do |task|
task.rotate = false
task.person_id = nil
task.save
end
@membership.destroy
flash[:notice] = 'You have successfully left the team.'
redirect_back
end


protected

Expand All @@ -59,14 +71,22 @@ def find_membership

def edit_access_required
if !@membership.editable_by?(session[:person])
flash[:notice] = "Sorry, you don't have permission to do that"
flash[:notice] = "Sorry, you don't have permission to do that."
redirect_back
end
end

def delete_access_required
if !@membership.deletable_by?(session[:person])
flash[:notice] = "Sorry, you don't have permission to do that"
flash[:notice] = "Sorry, you don't have permission to do that."
redirect_back
end
end

def delete_access_required_to_leave
@membership = Membership.find_by_team_id_and_person_id(params[:team_id], session[:person].id)
if !@membership.deletable_by?(session[:person])
flash[:notice] = "Sorry, you cannot do that."
redirect_back
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/membership.rb
Expand Up @@ -27,6 +27,7 @@ def editable_by?(person)
end

def deletable_by?(person)
return false if team.owned_by?(self.person)
return true if self.person == person
team.member?(person)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/task.rb
Expand Up @@ -247,6 +247,10 @@ def reschedule(datecompleted)

return flash_message
end

def self.assigned_to_person_in_team(person, team)
Task.find(:all, :conditions => {:person_id => person, :list_id => team.lists})
end


protected
Expand Down
4 changes: 4 additions & 0 deletions app/models/team.rb
Expand Up @@ -27,6 +27,10 @@ def member?(person)
end

def deletable_by?(person)
owned_by?(person)
end

def owned_by?(person)
self.person == person
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/memberships/new.haml
Expand Up @@ -9,6 +9,6 @@

- form_for(@membership, :url => person_memberships_path(@invitee)) do |f|
= f.label(:team_id)
= f.select(:team_id, session[:person].confirmed_teams.map{|t| [t.name, t.id]})
= f.select(:team_id, session[:person].confirmed_teams.sort_by(&:name).map{|t| [t.name, t.id]})

= f.submit('Invite')
8 changes: 1 addition & 7 deletions app/views/people/show.rhtml
Expand Up @@ -56,13 +56,7 @@
<tr>
<td><%= link_to_team(membership.team, 'picturelink') %></td>
<td>
<% if membership.confirmed != 1 %>
<%= " (awaiting confirmation)" %>
<% else %>
<% if @itsme == true %>
<%= link_to(image_tag('redx.png', :alt => 'Remove yourself from this team?', :title => 'Remove yourself from this team?'), { :controller => 'memberships', :action => 'remove', :id => membership.id, :returnto => 'person' }, :confirm => 'Are you sure you want to remove yourself from this team?') %>
<% end %>
<% end %>
<%= membership.confirmed? ? '&nbsp;' : ' (awaiting confirmation)' %>
</td>
</tr>
<% end %>
Expand Down
95 changes: 31 additions & 64 deletions app/views/teams/show.rhtml
Expand Up @@ -10,6 +10,10 @@
<li><a href='/teams/invite/<%= @team.id.to_s %>' class='picturelink person_invite'>Invite someone to join</a></li>
<li><a href='/teams/add_virtual/<%= @team.id.to_s %>' class='picturelink virtualperson_add'>Add a virtual member</a></li>

<% unless @team.owned_by?(session[:person]) -%>
<li><%= link_to('Leave team', leave_team_path(@team), :method => :delete, :class => 'picturelink team_leave', :confirm => "Are you sure you want to leave #{ javascript_safe(@team.name)}?") %></li>
<% end -%>
<% else -%>
<li><%= link_to('Request to join', memrequest_path(@team), :method => :post, :confirm => "Do you wish to make a request to join #{ javascript_safe(@team.name)}?", :class => 'picturelink membership_request') %></li>
<% end -%>
Expand All @@ -34,70 +38,33 @@
<% end %>


<% if @ismember == false %>

<tr>
<th>Team Members:</th>
<td>
<table>
<% unless @memberships.empty? %>
<% for membership in @memberships %>
<% if membership.person.usertype == 1 %>
<tr>
<td><%= link_to_person(membership.person, 'picturelink') %></td>
<td>
<% if membership.confirmed != 1 %>
<%= " (awaiting confirmation)" %>
<% end %>
</td>
</tr>
<% end %>
<% end %>
<% end %>

</table>
</td>
</tr>



<% else %>

<tr>
<th>Team Members:</th>
<td>
<table>
<% for membership in @memberships %>
<tr>
<td><%= link_to_person(membership.person, 'picturelink') %></td>
<td>
<% if membership.confirmed != 1 %>
<%= " (awaiting confirmation)" %>
<% else %>
<% if @imadeit == true %>
<%= link_to(image_tag('redx.png', :alt => 'Remove this person from your team?', :title => 'Remove this person from your team?'), { :controller => 'memberships', :action => 'remove', :id => membership.id, :returnto => 'team' }, :confirm => 'Are you sure you want to remove this person from your team?') %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
<% unless session[:person].nil? %>
<% unless @invitations.empty? %>
<% if is_confirmed_member_of_team(session[:person].id, @team.id) %>
<% for invitation in @invitations %>
<tr>
<td><%= invitation.email %></td>
<td><%= link_to(image_tag('envelope.jpg', :size => '17x11', :alt => 'Send a reminder email?', :title => 'Send a reminder email?'), { :controller => 'invitations', :action => 'remind', :id => invitation.code }, :confirm => 'Would you like to send this person a reminder email?') %> (click envelope to send a reminder)</td>
</tr>
<% end %>
<% end %>
<% end %>
<% end %>

</table>
</td>
</tr>
<tr>
<th>Team Members:</th>
<td>
<% @memberships.each do |membership| -%>
<p>
<%= link_to_person(membership.person, 'picturelink') %>
<%= ' (awaiting confirmation)' unless membership.confirmed? %>
</p>
<% end -%>
</td>
</tr>

<% if controller.logged_in? && @team.member?(session[:person]) -%>
<% if @invitations.any? -%>
<tr>
<th>Invitations:</th>
<td>
<% @invitations.each do |invitation| -%>
<p>
<%= invitation.email %>
<%= link_to(image_tag('envelope.jpg', :size => '17x11', :alt => 'Send a reminder email?', :title => 'Send a reminder email?'), { :controller => 'invitations', :action => 'remind', :id => invitation.code }, :confirm => 'Would you like to send this person a reminder email?') %>
</p>
<% end -%>
</td>
</tr>
<% end -%>

<tr>
<th>Lists:</th>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Expand Up @@ -6,7 +6,8 @@
map.resources :memberships, :member => {:accept => :put}

map.resources :teams, :member => {:workload => :get}
map.memrequest 'teams/:team_id/memberships/request', :controller => 'memberships', :action => 'memrequest'
map.memrequest 'teams/:team_id/memberships/request', :controller => 'memberships', :action => 'memrequest', :method => :post
map.leave_team 'teams/:team_id/leave', :controller => 'memberships', :action => 'leave', :method => :delete

map.resources :people do |person|
person.resources :memberships
Expand Down
33 changes: 33 additions & 0 deletions features/memberships.feature
Expand Up @@ -166,4 +166,37 @@ Feature: Memberships
Then I should NOT see the text 'Your request to join(.*)Household(.*)is pending'
And I should NOT see the task 'dust shelves'

Scenario: Members of a team can remove themselves from it
Given I am logged in as 'Chris'
When I view the team 'Household'
And I click on 'Leave team'
Then I should see the text 'You have successfully left the team'
And I should see a link to 'Request to join'
When I visit my home page
Then I should NOT see the task 'dust shelves'

Scenario: Members of a team can remove themselves from it
Given I am logged in as 'Chris'
When I view the team 'Household'
And I click on 'Leave team'
Then I should see the text 'You have successfully left the team'
And I should see a link to 'Request to join'
When I visit my home page
Then I should NOT see the task 'dust shelves'

Scenario: Tasks are reassigned when someone is removed
Given I am logged in as 'Chris'
And the task 'dust shelves' is assigned to 'Chris'
When I view the team 'Household'
And I click on 'Leave team'
Then I should see the text 'You have successfully left the team'
And the task 'dust shelves' should be assigned to the team

Scenario: Owner of the team cannot be removed
Given I am logged in as 'Alex'
When I view the team 'Household'
Then I should NOT see a link to 'Leave team'
When I try to remove myself from 'Household'
Then I should see the text 'Sorry, you cannot do that'
Then Alex should be a member of the team 'Household'

5 changes: 5 additions & 0 deletions features/step_definitions/task_steps.rb
Expand Up @@ -25,3 +25,8 @@
response.should_not have_tag('td', /^#{task}/)
end

Then /^the task '(.+)' should be assigned to the team$/ do |task|
task = Task.find_by_name(task)
task.person_id.should be_nil
end

5 changes: 5 additions & 0 deletions features/step_definitions/team_steps.rb
Expand Up @@ -35,6 +35,11 @@
visit team_path(team), :delete
end

When /^I try to remove myself from '(.+)'$/ do |teamname|
team = Team.find_by_name(teamname)
visit leave_team_path(team), :delete
end


Then /^(\w+) should be a member of the team '(.+)'$/ do |name, team|
p = Person.find_by_name(name)
Expand Down
Binary file added public/images/icons/team-leave.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions public/stylesheets/s2/planner2.css
Expand Up @@ -86,6 +86,10 @@ a.team_delete {
background-image: url('../../images/icons/team-delete.png');
}

a.team_leave {
background-image: url('../../images/icons/team-leave.png');
}

a.list {
background-image: url('../../images/icons/list-tiny.png');
}
Expand Down Expand Up @@ -244,6 +248,10 @@ td
padding: 0.2em;
}

#content td p {
margin-bottom: 0.5em;
}


span.bar-chart-bar {
border: 1px solid #aaaaaa;
Expand Down

0 comments on commit 7b5fe53

Please sign in to comment.