diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3bd7ed95a..5adf2bca1 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -4,8 +4,8 @@ class ProjectsController < ApplicationController load_and_authorize_resource def index - @projects = current_user.projects.paginate(:page => params[:page]) - #@projects = @projects.search(params[:query]).search_order if params[:query] + @projects = Project.accessible_by(current_ability, :members).recent.paginate(:page => params[:page]) + # @projects = @projects.search(params[:query]).search_order if params[:query] end def new diff --git a/app/models/ability.rb b/app/models/ability.rb index c122a37d0..6dbcfc8b0 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -30,8 +30,8 @@ class Ability cannot :create, RegisterRequest cannot :approve, RegisterRequest, :approved => true cannot :reject, RegisterRequest, :rejected => true - cannot [:owned, :related], BuildList - cannot [:owned, :related], Platform + cannot [:owned, :related], [BuildList, Platform] + cannot :members, Project end if user.user? @@ -50,7 +50,7 @@ class Ability can :read, Project, :visibility => 'open' can :read, Project, :owner_type => 'User', :owner_id => user.id can :read, Project, :owner_type => 'Group', :owner_id => user.group_ids - can(:read, Project, read_relations_for('projects')) {|project| local_reader? project} + can([:read, :members], Project, read_relations_for('projects')) {|project| local_reader? project} can(:write, Project) {|project| local_writer? project} # for grack can([:update, :sections, :manage_collaborators], Project) {|project| local_admin? project} can(:fork, Project) {|project| can? :read, project} diff --git a/app/models/relation.rb b/app/models/relation.rb index 6847b097b..9b2494f5c 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -9,6 +9,7 @@ class Relation < ActiveRecord::Base # validate { errors.add(:object, :taken) if Relation.where(:object_type => self.object_type, :object_id => self.object_id).present? } before_validation :add_default_role + scope :by_user_through_groups, lambda {|u| where("object_type = 'User' AND object_id = ? OR object_type = 'Group' AND object_id IN (?)", u.id, u.group_ids)} scope :by_object, lambda {|obj| {:conditions => ['object_id = ? AND object_type = ?', obj.id, obj.class.to_s]}} scope :by_target, lambda {|tar| {:conditions => ['target_id = ? AND target_type = ?', tar.id, tar.class.to_s]}} scope :by_role, lambda {|role| {:conditions => ['role = ?', role]}} diff --git a/app/views/projects/_project.html.haml b/app/views/projects/_project.html.haml index af40875a3..1e4891e38 100644 --- a/app/views/projects/_project.html.haml +++ b/app/views/projects/_project.html.haml @@ -4,5 +4,5 @@ .table-sort-left= image_tag visibility_icon(project.visibility) .table-sort-right #{project.owner.uname} / #{project.name} %td.td2= project.description - %td= t("layout.collaborators.role_names.#{project.relations.by_object(current_user).first.role}") - %td.td5= link_to image_tag('x.png'), remove_user_project_path(project), :method => :delete, :confirm => t("layout.confirm") \ No newline at end of file + %td= t("layout.collaborators.role_names.#{project.relations.by_user_through_groups(current_user).first.role}") + %td.td5= link_to image_tag('x.png'), remove_user_project_path(project), :method => :delete, :confirm => t("layout.confirm") unless project.owner == current_user \ No newline at end of file