Class: IssueTagsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/issue_tags_controller.rb

Instance Method Summary collapse

Instance Method Details

#editObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/issue_tags_controller.rb', line 6

def edit
  return unless AdditionalTags.setting?(:active_issue_tags) &&
                User.current.allowed_to?(:edit_issue_tags, @projects.first)

  @issue_ids = params[:ids]
  @is_bulk_editing = @issue_ids.size > 1
  @issue_tags = if @is_bulk_editing
                  issues = @issues.map(&:tag_list)
                  issues.flatten!
                  issues.uniq
                else
                  @issues.first.tag_list
                end

  @issue_tags.sort!
  @most_used_tags = Issue.available_tags.most_used 10
  @append = params[:append] == 'true'
end

#updateObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/issue_tags_controller.rb', line 25

def update
  if AdditionalTags.setting?(:active_issue_tags) &&
     User.current.allowed_to?(:edit_issue_tags, @projects.first)
    tags = params[:issue] && params[:issue][:tag_list] ? params[:issue][:tag_list].reject(&:empty?) : []

    unless User.current.allowed_to?(:create_issue_tags, @projects.first) || Issue.allowed_tags?(tags)
      flash[:error] = t :notice_failed_to_add_tags
      return
    end

    Issue.transaction do
      @issues.each do |issue|
        issue.init_journal User.current
        # add tags added in placeholder for a single/multiple issue or overwrite tags for single issue
        params[:append] == 'true' ? issue.tag_list << tags : issue.tag_list = tags

        issue.tags_to_journal issue.tag_list_was&.to_s, issue.tag_list.to_s
        issue.save!
      end
    end
    flash[:notice] = t :notice_tags_added
  else
    flash[:error] = t :notice_failed_to_add_tags
  end
rescue StandardError => e
  Rails.logger.warn "Failed to add tags: #{e.inspect}"
  flash[:error] = t :notice_failed_to_add_tags
ensure
  redirect_to_referer_or { render text: 'Tags updated.', layout: true }
end