diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index edf4e9e5d78..16f04305a43 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -94,7 +94,6 @@ module Issuable acts_as_paranoid - after_save :update_assignee_cache_counts, if: :assignee_id_changed? after_save :record_metrics, unless: :imported? # We want to use optimistic lock for cases when only title or description are involved diff --git a/app/services/members/authorized_destroy_service.rb b/app/services/members/authorized_destroy_service.rb index 1711be7211c..a85b9465c84 100644 --- a/app/services/members/authorized_destroy_service.rb +++ b/app/services/members/authorized_destroy_service.rb @@ -26,15 +26,22 @@ module Members def unassign_issues_and_merge_requests(member) if member.is_a?(GroupMember) - IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). - execute. - update_all(assignee_id: nil) + issue_ids = IssuesFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). + execute.pluck(:id) + + IssueAssignee.destroy_all(issue_id: issue_ids, user_id: member.user_id) + MergeRequestsFinder.new(user, group_id: member.source_id, assignee_id: member.user_id). execute. update_all(assignee_id: nil) else project = member.source - project.issues.opened.assigned_to(member.user).update_all(assignee_id: nil) + + IssueAssignee.destroy_all( + user_id: member.user_id, + issue_id: project.issues.opened.assigned_to(member.user).select(:id) + ) + project.merge_requests.opened.assigned_to(member.user).update_all(assignee_id: nil) member.user.update_cache_counts end diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index 1dee791cfd6..fb1f56c9cc6 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -84,7 +84,7 @@ module SystemNoteService "assigned to #{issue.assignees.map(&:to_reference).to_sentence}" end - NoteSummary.new(issue, project, author, body, action: 'assignee') + create_note(NoteSummary.new(issue, project, author, body, action: 'assignee')) end # Called when one or more labels on a Noteable are added and/or removed diff --git a/db/migrate/20170320171632_create_issue_assignees_table.rb b/db/migrate/20170320171632_create_issue_assignees_table.rb index 72b70baa8d9..23b8da37b6d 100644 --- a/db/migrate/20170320171632_create_issue_assignees_table.rb +++ b/db/migrate/20170320171632_create_issue_assignees_table.rb @@ -26,7 +26,7 @@ class CreateIssueAssigneesTable < ActiveRecord::Migration # disable_ddl_transaction! def up - create_table :issue_assignees, id: false do |t| + create_table :issue_assignees do |t| t.references :user, foreign_key: { on_delete: :cascade }, index: true, null: false t.references :issue, foreign_key: { on_delete: :cascade }, null: false end diff --git a/db/schema.rb b/db/schema.rb index 340d4064c02..7b960f79c1f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -452,7 +452,7 @@ ActiveRecord::Schema.define(version: 20170502091007) do add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree - create_table "issue_assignees", id: false, force: :cascade do |t| + create_table "issue_assignees", force: :cascade do |t| t.integer "user_id", null: false t.integer "issue_id", null: false end diff --git a/lib/github/import.rb b/lib/github/import.rb index d49761fd6c6..06beb607a3e 100644 --- a/lib/github/import.rb +++ b/lib/github/import.rb @@ -245,7 +245,7 @@ module Github issue.label_ids = label_ids(representation.labels) issue.milestone_id = milestone_id(representation.milestone) issue.author_id = author_id - issue.assignee_id = user_id(representation.assignee) + issue.assignee_ids = [user_id(representation.assignee)] issue.created_at = representation.created_at issue.updated_at = representation.updated_at issue.save!(validate: false) diff --git a/spec/features/dashboard/issuables_counter_spec.rb b/spec/features/dashboard/issuables_counter_spec.rb index 3d536c5ba40..6f7bf0eba6e 100644 --- a/spec/features/dashboard/issuables_counter_spec.rb +++ b/spec/features/dashboard/issuables_counter_spec.rb @@ -19,6 +19,8 @@ describe 'Navigation bar counter', feature: true, caching: true do issue.assignees = [] + user.update_cache_counts + Timecop.travel(3.minutes.from_now) do visit issues_path diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb index e6bf77aee6a..96151689359 100644 --- a/spec/finders/issues_finder_spec.rb +++ b/spec/finders/issues_finder_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' describe IssuesFinder do - let(:user) { create(:user) } - let(:user2) { create(:user) } - let(:project1) { create(:empty_project) } - let(:project2) { create(:empty_project) } - let(:milestone) { create(:milestone, project: project1) } - let(:label) { create(:label, project: project2) } - let(:issue1) { create(:issue, author: user, assignees: [user], project: project1, milestone: milestone, title: 'gitlab') } - let(:issue2) { create(:issue, author: user, assignees: [user], project: project2, description: 'gitlab') } - let(:issue3) { create(:issue, author: user2, assignees: [user2], project: project2, title: 'tanuki', description: 'tanuki') } + set(:user) { create(:user) } + set(:user2) { create(:user) } + set(:project1) { create(:empty_project) } + set(:project2) { create(:empty_project) } + set(:milestone) { create(:milestone, project: project1) } + set(:label) { create(:label, project: project2) } + set(:issue1) { create(:issue, author: user, assignees: [user], project: project1, milestone: milestone, title: 'gitlab') } + set(:issue2) { create(:issue, author: user, assignees: [user], project: project2, description: 'gitlab') } + set(:issue3) { create(:issue, author: user2, assignees: [user2], project: project2, title: 'tanuki', description: 'tanuki') } describe '#execute' do - let(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') } - let!(:label_link) { create(:label_link, label: label, target: issue2) } + set(:closed_issue) { create(:issue, author: user2, assignees: [user2], project: project2, state: 'closed') } + set(:label_link) { create(:label_link, label: label, target: issue2) } let(:search_user) { user } let(:params) { {} } let(:issues) { described_class.new(search_user, params.reverse_merge(scope: scope, state: 'opened')).execute } diff --git a/spec/requests/api/v3/issues_spec.rb b/spec/requests/api/v3/issues_spec.rb index 49191b2eb4e..cc81922697a 100644 --- a/spec/requests/api/v3/issues_spec.rb +++ b/spec/requests/api/v3/issues_spec.rb @@ -1157,38 +1157,6 @@ describe API::V3::Issues do end end - describe 'PUT /projects/:id/issues/:issue_id to update weight' do - it 'updates an issue with no weight' do - put v3_api("/projects/#{project.id}/issues/#{issue.id}", user), weight: 5 - - expect(response).to have_http_status(200) - expect(json_response['weight']).to eq(5) - end - - it 'removes a weight from an issue' do - weighted_issue = create(:issue, project: project, weight: 2) - - put v3_api("/projects/#{project.id}/issues/#{weighted_issue.id}", user), weight: nil - - expect(response).to have_http_status(200) - expect(json_response['weight']).to be_nil - end - - it 'returns 400 if weight is less than minimum weight' do - put v3_api("/projects/#{project.id}/issues/#{issue.id}", user), weight: -1 - - expect(response).to have_http_status(400) - expect(json_response['error']).to eq('weight does not have a valid value') - end - - it 'returns 400 if weight is more than maximum weight' do - put v3_api("/projects/#{project.id}/issues/#{issue.id}", user), weight: 10 - - expect(response).to have_http_status(400) - expect(json_response['error']).to eq('weight does not have a valid value') - end - end - describe "DELETE /projects/:id/issues/:issue_id" do it "rejects a non member from deleting an issue" do delete v3_api("/projects/#{project.id}/issues/#{issue.id}", non_member) diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb index 5f1b82e8355..68816bf36b8 100644 --- a/spec/services/system_note_service_spec.rb +++ b/spec/services/system_note_service_spec.rb @@ -164,7 +164,9 @@ describe SystemNoteService, services: true do let(:assignee2) { create(:user) } let(:assignee3) { create(:user) } - it_behaves_like 'a system note' + it_behaves_like 'a system note' do + let(:action) { 'assignee' } + end def build_note(old_assignees, new_assignees) issue.assignees = new_assignees diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index 8aa900d1a75..de37a61e388 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -60,7 +60,7 @@ describe Users::DestroyService, services: true do it 'migrates the issue so that it is "Unassigned"' do migrated_issue = Issue.find_by_id(issue.id) - expect(migrated_issue.assignees).to be_nil + expect(migrated_issue.assignees).to be_empty end end end