Class: Projects::IssuesController

Inherits:
ApplicationController show all
Includes:
IssuableActions, ToggleSubscriptionAction
Defined in:
app/controllers/projects/issues_controller.rb

Instance Method Summary collapse

Methods included from IssuableActions

#destroy

Methods included from ToggleSubscriptionAction

#toggle_subscription

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#bulk_updateObject


156
157
158
159
# File 'app/controllers/projects/issues_controller.rb', line 156

def bulk_update
  result = Issues::BulkUpdateService.new(project, current_user, bulk_update_params).execute
  redirect_back_or_default(default: { action: 'index' }, options: { notice: "#{result[:count]} issues updated" })
end

#can_create_branchObject


144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/projects/issues_controller.rb', line 144

def can_create_branch
  can_create = current_user &&
    can?(current_user, :push_code, @project) &&
    @issue.can_be_worked_on?(current_user)

  respond_to do |format|
    format.json do
      render json: { can_create_branch: can_create }
    end
  end
end

#createObject


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/projects/issues_controller.rb', line 77

def create
  @issue = Issues::CreateService.new(project, current_user, issue_params).execute

  respond_to do |format|
    format.html do
      if @issue.valid?
        redirect_to issue_path(@issue)
      else
        render :new
      end
    end
    format.js do |format|
      @link = @issue.attachment.url.to_js
    end
  end
end

#editObject


59
60
61
# File 'app/controllers/projects/issues_controller.rb', line 59

def edit
  respond_with(@issue)
end

#indexObject


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/projects/issues_controller.rb', line 23

def index
  terms = params['issue_search']
  @issues = get_issues_collection

  if terms.present?
    if terms =~ /\A#(\d+)\z/
      @issues = @issues.where(iid: $1)
    else
      @issues = @issues.full_search(terms)
    end
  end

  @issues = @issues.page(params[:page])
  @labels = @project.labels.where(title: params[:label_name])

  respond_to do |format|
    format.html
    format.atom { render layout: false }
    format.json do
      render json: {
        html: view_to_html_string("projects/issues/_issues"),
        labels: @labels.as_json(methods: :text_color)
      }
    end
  end
end

#newObject


50
51
52
53
54
55
56
57
# File 'app/controllers/projects/issues_controller.rb', line 50

def new
  params[:issue] ||= ActionController::Parameters.new(
    assignee_id: ""
  )

  @issue = @noteable = @project.issues.new(issue_params)
  respond_with(@issue)
end

#referenced_merge_requestsObject


119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/controllers/projects/issues_controller.rb', line 119

def referenced_merge_requests
  @merge_requests = @issue.referenced_merge_requests(current_user)
  @closed_by_merge_requests = @issue.closed_by_merge_requests(current_user)

  respond_to do |format|
    format.json do
      render json: {
        html: view_to_html_string('projects/issues/_merge_requests')
      }
    end
  end
end

132
133
134
135
136
137
138
139
140
141
142
# File 'app/controllers/projects/issues_controller.rb', line 132

def related_branches
  @related_branches = @issue.related_branches(current_user)

  respond_to do |format|
    format.json do
      render json: {
        html: view_to_html_string('projects/issues/_related_branches')
      }
    end
  end
end

#showObject


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/projects/issues_controller.rb', line 63

def show
  @note     = @project.notes.new(noteable: @issue)
  @notes    = @issue.notes.nonawards.with_associations.fresh
  @noteable = @issue

  respond_to do |format|
    format.html
    format.json do
      render json: @issue.to_json(include: [:milestone, :labels])
    end
  end

end

#updateObject


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/projects/issues_controller.rb', line 94

def update
  @issue = Issues::UpdateService.new(project, current_user, issue_params).execute(issue)

  if params[:move_to_project_id].to_i > 0
    new_project = Project.find(params[:move_to_project_id])
    return render_404 unless issue.can_move?(current_user, new_project)

    move_service = Issues::MoveService.new(project, current_user)
    @issue = move_service.execute(@issue, new_project)
  end

  respond_to do |format|
    format.html do
      if @issue.valid?
        redirect_to issue_path(@issue)
      else
        render :edit
      end
    end
    format.json do
      render json: @issue.to_json(include: { milestone: {}, assignee: { methods: :avatar_url }, labels: { methods: :text_color } })
    end
  end
end