Commit 623d2f25 authored by Jean-Philippe Lang's avatar Jean-Philippe Lang

Projects menu item now shows the list of public projects and projects for which…

Projects menu item now shows the list of public projects and projects for which the user is a member (marked with a star).
If current user is admin, private projects are also listed.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@460 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 634d3557
......@@ -41,12 +41,12 @@ class ProjectsController < ApplicationController
def list
sort_init "#{Project.table_name}.name", "asc"
sort_update
@project_count = Project.count(:all, :conditions => ["is_public=?", true])
@project_count = Project.count(:all, :conditions => Project.visible_by(logged_in_user))
@project_pages = Paginator.new self, @project_count,
15,
params['page']
@projects = Project.find :all, :order => sort_clause,
:conditions => ["#{Project.table_name}.is_public=?", true],
:conditions => Project.visible_by(logged_in_user),
:include => :parent,
:limit => @project_pages.items_per_page,
:offset => @project_pages.current.offset
......
......@@ -69,7 +69,9 @@ class Project < ActiveRecord::Base
end
def self.visible_by(user=nil)
if user && !user.memberships.empty?
if user && user.admin?
return nil
elsif user && !user.memberships.empty?
return ["#{Project.table_name}.is_public = ? or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true]
else
return ["#{Project.table_name}.is_public = ?", true]
......
<h2><%=l(:label_public_projects)%></h2>
<h2><%=l(:label_project_plural)%></h2>
<table class="list">
<thead><tr>
<%= sort_header_tag("#{Project.table_name}.name", :caption => l(:label_project)) %>
<th><%=l(:field_description)%></th>
<th><%=l(:field_parent)%></th>
<%= sort_header_tag("#{Project.table_name}.created_on", :caption => l(:field_created_on)) %>
</tr></thead>
<tbody>
<% for project in @projects %>
<tr class="<%= cycle("odd", "even") %>">
<td><%= link_to project.name, :action => 'show', :id => project %></td>
<td><%=h project.description %></td>
<td>
<%= link_to project.name, {:action => 'show', :id => project}, :class => (@logged_in_user && @logged_in_user.role_for_project(project) ? "icon icon-fav" : "") %><br />
<%=h project.description %>
</td>
<td><%= link_to(project.parent.name, :action => 'show', :id => project.parent) unless project.parent.nil? %></td>
<td align="center"><%= format_date(project.created_on) %></td>
</tr>
......@@ -19,5 +20,11 @@
</tbody>
</table>
<% if @logged_in_user %>
<div class="contextual">
<span class="icon icon-fav"><%= l(:label_my_projects) %></span>
</div>
<% end %>
<%= pagination_links_full @project_pages %>
[ <%= @project_pages.current.first_item %> - <%= @project_pages.current.last_item %> / <%= @project_count %> ]
\ No newline at end of file
[ <%= @project_pages.current.first_item %> - <%= @project_pages.current.last_item %> / <%= @project_count %> ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment