# Returns a SQL conditions string used to find all issues visible by the specified user
def self.visible_condition(user, options={})
Project.allowed_to_condition(user, :view_issues, options) do |role, user|
- case role.issues_visibility
- when 'all'
- nil
- when 'default'
- if user.logged?
+ if user.logged?
+ case role.issues_visibility
+ when 'all'
+ nil
+ when 'default'
user_ids = [user.id] + user.groups.map(&:id)
"(#{table_name}.is_private = #{connection.quoted_false} OR #{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
- else
- "(#{table_name}.is_private = #{connection.quoted_false})"
- end
- when 'own'
- if user.logged?
+ when 'own'
user_ids = [user.id] + user.groups.map(&:id)
"(#{table_name}.author_id = #{user.id} OR #{table_name}.assigned_to_id IN (#{user_ids.join(',')}))"
else
'1=0'
end
else
- '1=0'
+ "(#{table_name}.is_private = #{connection.quoted_false})"
end
end
end
# Returns true if usr or current user is allowed to view the issue
def visible?(usr=nil)
(usr || User.current).allowed_to?(:view_issues, self.project) do |role, user|
- case role.issues_visibility
- when 'all'
- true
- when 'default'
- !self.is_private? || (user.logged? && (self.author == user || user.is_or_belongs_to?(assigned_to)))
- when 'own'
- user.logged? && (self.author == user || user.is_or_belongs_to?(assigned_to))
+ if user.logged?
+ case role.issues_visibility
+ when 'all'
+ true
+ when 'default'
+ !self.is_private? || (self.author == user || user.is_or_belongs_to?(assigned_to))
+ when 'own'
+ self.author == user || user.is_or_belongs_to?(assigned_to)
+ else
+ false
+ end
else
- false
+ !self.is_private?
end
end
end
<%= error_messages_for 'role' %>
+<% unless @role.anonymous? %>
<div class="box tabular">
<% unless @role.builtin? %>
<p><%= f.text_field :name, :required => true %></p>
<%= select_tag(:copy_workflow_from, content_tag("option") + options_from_collection_for_select(@roles, :id, :name, params[:copy_workflow_from] || @copy_from.try(:id))) %></p>
<% end %>
</div>
+<% end %>
<h3><%= l(:label_permissions) %></h3>
<div class="box tabular" id="permissions">
assert_response :success
assert_template 'edit'
assert_equal Role.find(1), assigns(:role)
+ assert_select 'select[name=?]', 'role[issues_visibility]'
+ end
+
+ def test_edit_anonymous
+ get :edit, :id => Role.anonymous.id
+ assert_response :success
+ assert_template 'edit'
+ assert_select 'select[name=?]', 'role[issues_visibility]', 0
end
def test_edit_invalid_should_respond_with_404