Actions
Defect #44414
openVisibility of watcher users
Status:
New
Priority:
Normal
Assignee:
-
Category:
Issues
Target version:
-
Resolution:
Affected version:
Description
Hello!
I faced up with issue to display visible watchers.
In acts_as_watchable.rb:
# array of watchers that the given user is allowed to see
def visible_watcher_users(user = User.current)
if user.allowed_to?(:"view_#{self.class.name.underscore}_watchers", project)
watcher_users
else
# without permission, the user can only see themselves (if they're a watcher)
watcher_users & [user]
end
end
I think that proper way to show visible users should be:
# array of watchers that the given user is allowed to see
def visible_watcher_users(user = User.current)
if user.allowed_to?(:"view_#{self.class.name.underscore}_watchers", project)
watcher_users.visible # This scope show all available users for user/User.current
else
# without permission, the user can only see themselves (if they're a watcher)
watcher_users & [user]
end
end
Also should be changed in views/watchers/_watchers.html.erb
<% watched_klass_name = watched.class.name.underscore -%>
<% if User.current.allowed_to?(:"add_#{watched_klass_name}_watchers", watched.project) %>
<div class="contextual">
<%= link_to l(:button_add),
new_watchers_path(:object_type => watched_klass_name, :object_id => watched),
:remote => true,
:method => 'get' %>
</div>
<% end %>
<% if User.current.allowed_to?(:"view_#{watched_klass_name}_watchers", watched.project) %>
<h3><%= l(:"label_#{watched_klass_name}_watchers") %> (<%= watched.visible_watcher_users.size %>)</h3>
<%= watchers_list(watched) %>
<% else %>
<h3><%= l(:"label_#{watched_klass_name}_watchers") %></h3>
<% end %>
And in helpers/watchers_helper.rb:
def watchers_list(object)
remove_allowed = User.current.allowed_to?(:"delete_#{object.class.name.underscore}_watchers", object.project)
content = ''.html_safe
scope = object.visible_watcher_users
scope = scope.includes(:email_address) if Setting.gravatar_enabled?
lis = scope.sorted.collect do |user|
s = ''.html_safe
s << avatar(user, :size => "16").to_s if user.is_a?(User)
s << link_to_principal(user, class: user.class.to_s.downcase)
if object.respond_to?(:visible?) && user.is_a?(User) && !object.visible?(user)
s << content_tag('span', sprite_icon('warning', l(:notice_invalid_watcher)), class: 'icon-only icon-warning', title: l(:notice_invalid_watcher))
end
if remove_allowed
url = {:controller => 'watchers',
:action => 'destroy',
:object_type => object.class.to_s.underscore,
:object_id => object.id,
:user_id => user}
s << ' '
s << link_to(sprite_icon('link-break', l(:button_remove)), url,
:remote => true, :method => 'delete',
:class => "delete icon-only icon-link-break",
:title => l(:button_remove))
end
content << content_tag('li', s, :class => "user-#{user.id}")
end
content.present? ? content_tag('ul', content, :class => 'watchers') : content
end
If my guesses are correct, I can prepare a patch to fix this behaviour
No data to display
Actions