Index: app/controllers/my_controller.rb =================================================================== --- app/controllers/my_controller.rb (revision 142) +++ app/controllers/my_controller.rb (working copy) @@ -157,4 +157,31 @@ session[:page_layout] = nil redirect_to :action => 'page' end + + # (dis)Join to a project + # params[:id] : the project's id + # params[:confirm] = 1 : ok, confirm the change + def join + @user = User.current + @project = Project.find(params[:id]) + @confirm = params[:confirm].to_i + @memberships = @user.memberships + + if @confirm == 1 + if @user.member_of?(@project) + membership = Member.find :first, :conditions => ['user_id = ? and project_id =? ', @user.id, @project.id] + membership_id = membership.id + membership.destroy unless membership.nil? + @memberships.delete_if {|m| m.id == membership_id } + else + @role = Role.find :first, :conditions => ['name = ?', 'User'] + membership = Member.new :user_id => @user.id, + :project_id => @project.id, :mail_notification => true, + :role_id => @role.id, :created_on => Time.now + if membership.save + @memberships << membership + end + end + end + end end Index: app/controllers/projects_controller.rb =================================================================== --- app/controllers/projects_controller.rb (revision 142) +++ app/controllers/projects_controller.rb (working copy) @@ -22,7 +22,7 @@ menu_item :files, :only => [:list_files, :add_file] menu_item :settings, :only => :settings menu_item :issues, :only => [:changelog] - + before_filter :find_project, :except => [ :index, :list, :add, :activity ] before_filter :find_optional_project, :only => :activity before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy, :activity ] @@ -220,7 +220,7 @@ retrieve_selected_tracker_ids(@trackers) @versions = @project.versions.sort end - + def roadmap @trackers = @project.trackers.find(:all, :conditions => ["is_in_roadmap=?", true]) retrieve_selected_tracker_ids(@trackers) Index: app/views/projects/index.rhtml =================================================================== --- app/views/projects/index.rhtml (revision 142) +++ app/views/projects/index.rhtml (working copy) @@ -7,13 +7,20 @@

<%=l(:label_project_plural)%>

<% @project_tree.keys.sort.each do |project| %> -

<%= link_to h(project.name), {:action => 'show', :id => project}, :class => (User.current.member_of?(project) ? "icon icon-fav" : "") %>

+

+ <%= link_to h(project.name), {:action => 'show', :id => project}, :class => (User.current.member_of?(project) ? "icon icon-fav" : "") %> + (<%= link_to (User.current.member_of?(project) ? "disjoin" : "join"), {:controller => 'my', :action => 'join', :id => project} %>) +

<%= textilizable(project.short_description, :project => project) %> <% if @project_tree[project].any? %>

<%= l(:label_subproject_plural) %>: <%= @project_tree[project].sort.collect {|subproject| - link_to(h(subproject.name), {:action => 'show', :id => subproject}, :class => (User.current.member_of?(subproject) ? "icon icon-fav" : ""))}.join(', ') %>

+ link_to(h(subproject.name), {:action => 'show', :id => subproject}, :class => (User.current.member_of?(subproject) ? "icon icon-fav" : "")) + + ' (' + link_to( (User.current.member_of?(subproject) ? "disjoin" : "join"), {:controller => 'my', :action => 'join', :id => subproject} ) + ')' + }.join(', ') + %> +

<% end %> <% end %> Index: app/views/projects/show.rhtml =================================================================== --- app/views/projects/show.rhtml (revision 142) +++ app/views/projects/show.rhtml (working copy) @@ -44,7 +44,9 @@ <%= users[0,25].collect(&:user).collect{|u| link_to_user u}.join(", ") %> <%= "... (#{users.size} total)" if users.size > 25 -%>
- <% end %>

+ <% end %> + Your membership: <%= link_to User.current.member_of?(@project) ? "DisJoin" : "Join", :controller => 'my', :action => 'join', :id => @project %> +

<% end %>