78 |
78 |
|
79 |
79 |
named_scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
|
80 |
80 |
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
81 |
|
named_scope :all_public, { :conditions => { :is_public => true } }
|
|
81 |
named_scope :all_public, lambda { { :conditions => Project.is_public } }
|
82 |
82 |
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
|
83 |
83 |
|
84 |
84 |
def identifier=(identifier)
|
... | ... | |
95 |
95 |
find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
|
96 |
96 |
end
|
97 |
97 |
|
|
98 |
def is_public?
|
|
99 |
user = User.current
|
|
100 |
ee_group = Group.find_by_lastname('ee')
|
|
101 |
if user && ee_group && user.group_ids.include?(ee_group.id)
|
|
102 |
return true
|
|
103 |
else
|
|
104 |
return false
|
|
105 |
end
|
|
106 |
end
|
|
107 |
|
98 |
108 |
# Returns a SQL :conditions string used to find all active projects for the specified user.
|
99 |
109 |
#
|
100 |
110 |
# Examples:
|
... | ... | |
102 |
112 |
# Projects.visible_by(normal_user) => "projects.status = 1 AND projects.is_public = 1"
|
103 |
113 |
def self.visible_by(user=nil)
|
104 |
114 |
user ||= User.current
|
|
115 |
ee_group = Group.find_by_lastname('ee')
|
105 |
116 |
if user && user.admin?
|
106 |
117 |
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
|
118 |
elsif user && ee_group && user.group_ids.include?(ee_group.id)
|
|
119 |
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
107 |
120 |
elsif user && user.memberships.any?
|
108 |
121 |
return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))"
|
109 |
122 |
else
|
... | ... | |
112 |
125 |
end
|
113 |
126 |
|
114 |
127 |
def self.allowed_to_condition(user, permission, options={})
|
|
128 |
ee_group = Group.find_by_lastname('ee')
|
115 |
129 |
statements = []
|
116 |
130 |
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
117 |
131 |
if perm = Redmine::AccessControl.permission(permission)
|
... | ... | |
130 |
144 |
else
|
131 |
145 |
statements << "1=0"
|
132 |
146 |
if user.logged?
|
133 |
|
if Role.non_member.allowed_to?(permission) && !options[:member]
|
134 |
|
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}"
|
|
147 |
if Role.non_member.allowed_to?(permission) && !options[:member] && user.group_ids.include?(ee_group.id)
|
|
148 |
statements << "1=1"
|
135 |
149 |
end
|
136 |
150 |
allowed_project_ids = user.memberships.select {|m| m.roles.detect {|role| role.allowed_to?(permission)}}.collect {|m| m.project_id}
|
137 |
151 |
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any?
|