Project

General

Profile

Patch #38792 » enable_removing_watchers_in_bulk_context_menu.patch

salman mp, 2023-06-28 18:37

View differences:

app/controllers/context_menus_controller.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/controllers/context_menus_controller.rb (revision 41653+:c704208ed465+)
36 36
      :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
37 37
      :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
38 38
      :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
39
      :delete_watchers => User.current.allowed_to?(:delete_issue_watchers, @projects),
39 40
      :delete => @issues.all?(&:deletable?),
40 41
      :add_subtask => @issue && !@issue.closed? && User.current.allowed_to?(:manage_subtasks, @project)
41 42
    }
app/controllers/watchers_controller.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/controllers/watchers_controller.rb (revision 41653+:c704208ed465+)
18 18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 19

  
20 20
class WatchersController < ApplicationController
21
  before_action :require_login, :find_watchables, :only => [:watch, :unwatch]
21
  before_action :require_login, :find_watchables, :only => [:watch, :unwatch, :bulk_delete]
22 22

  
23 23
  def watch
24 24
    set_watcher(@watchables, User.current, true)
......
70 70
    end
71 71
  end
72 72

  
73
  def bulk_delete
74
    if request.method == "POST"
75
      return unless params[:watcher].present?
76

  
77
      user_ids = params[:watcher][:user_ids] || [params[:watcher][:user_id]]
78
      @users = Principal.where(:id => user_ids).to_a
79
      @users.each do |user|
80
        @watchables.each do |watchable|
81
          watchable.set_watcher(user, false)
82
        end
83
      end
84
      respond_to do |format|
85
        format.js
86
        format.api {render_api_ok}
87
      end
88
    elsif request.method == "GET"
89
      if params["object_id"].present?
90
        @users = Watcher.where(watchable_id: params["object_id"]).all.map { |w| w.user }.uniq
91
      else
92
        @users = Principal.assignable_watchers
93
      end
94
    end
95
  end
96

  
73 97
  def destroy
74 98
    user = Principal.find(params[:user_id])
75 99
    @watchables.each do |watchable|
app/views/context_menus/issues.html.erb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → app/views/context_menus/issues.html.erb (revision 41653+:c704208ed465+)
133 133
                new_watchers_path(:object_type => 'issue', :object_id => @issue_ids),
134 134
                :remote => true,
135 135
                :class => 'icon icon-add' %></li>
136
      <li><%= context_menu_link l(:button_delete),
137
                bulk_delete_watchers_dialog_path(:object_type => 'issue', :object_id => @issue_ids),
138
                :remote => true,
139
                :class => 'icon icon-del' %></li>
136 140
    </ul>
137 141
  </li>
138 142
<% end %>
/dev/null (revision 41653+:c704208ed465+) → app/views/watchers/_bulk_delete.html.erb (revision 41653+:c704208ed465+)
1
<%
2
title =
3
  if watchables.present?
4
    l(:"permission_delete_#{watchables.first.class.name.underscore}_watchers")
5
  else
6
    l(:permission_delete_issue_watchers)
7
  end
8
-%>
9
<h3 class="title"><%= title %></h3>
10

  
11
<%= form_tag(bulk_delete_watchers_path,
12
             :remote => true,
13
             :method => :post,
14
             :id => 'new-watcher-form') do %>
15

  
16
  <% if watchables.present? %>
17
    <%= hidden_field_tag 'object_type', watchables.first.class.name.underscore %>
18
    <% watchables.each do |watchable| %>
19
      <%= hidden_field_tag 'object_id[]', watchable.id %>
20
    <% end  %>
21
  <% end %>
22
  <%= hidden_field_tag 'project_id', @project.id if @project %>
23

  
24
  <p><%= label_tag 'user_search', l(:label_user_search) %><%= text_field_tag 'user_search', nil %></p>
25
  <%= javascript_tag(
26
        "observeSearchfield(
27
          'user_search',
28
          'users_for_watcher',
29
          '#{escape_javascript(
30
               url_for(
31
                 :controller => 'watchers',
32
                 :action => 'autocomplete_for_user',
33
                 :object_type => (watchables.present? ? watchables.first.class.name.underscore : nil),
34
                 :object_id => (watchables.present? ? watchables.map(&:id) : nil),
35
                 :project_id => @project
36
               )
37
             )}'
38
         )"
39
       ) %>
40
  <div id="users_for_watcher">
41
    <%= principals_check_box_tags('watcher[user_ids][]', users) %>
42
  </div>
43

  
44
  <p class="buttons">
45
    <%= submit_tag l(:button_delete), :name => nil, :onclick => "hideModal(this);" %>
46
    <%= link_to_function l(:button_cancel), "hideModal(this);" %>
47
  </p>
48
<% end %>
/dev/null (revision 41653+:c704208ed465+) → app/views/watchers/bulk_delete.js.erb (revision 41653+:c704208ed465+)
1
<% if request.method == "GET" %>
2
  $('#ajax-modal').html(
3
  '<%= escape_javascript(
4
         render(:partial => 'watchers/bulk_delete',
5
                :locals => { :watchables => @watchables, :users => @users })
6
       ) %>');
7
  showModal('ajax-modal', '400px');
8
  $('#ajax-modal').addClass('delete-watchers');
9
<% end %>
config/routes.rb (revision 41653:c704208ed465fcb5f84cbfa7b6d4050e229d081b) → config/routes.rb (revision 41653+:c704208ed465+)
116 116
  post 'watchers/watch', :to => 'watchers#watch', :as => 'watch'
117 117
  delete 'watchers/watch', :to => 'watchers#unwatch'
118 118
  get 'watchers/new', :to => 'watchers#new', :as => 'new_watchers'
119
  get 'watchers/delete', :to => 'watchers#bulk_delete', :as => 'bulk_delete_watchers_dialog'
120
  post 'watchers/bulk_delete', :to => 'watchers#bulk_delete', :as => 'bulk_delete_watchers'
119 121
  post 'watchers', :to => 'watchers#create'
120 122
  post 'watchers/append', :to => 'watchers#append'
121 123
  delete 'watchers', :to => 'watchers#destroy'
    (1-1/1)