FIX: unable to delete user belonging to a group that grants a trust level
This commit is contained in:
parent
135195363b
commit
5ce8177662
|
@ -50,6 +50,11 @@ class User < ActiveRecord::Base
|
|||
has_many :email_change_requests, dependent: :destroy
|
||||
has_many :directory_items, dependent: :delete_all
|
||||
has_many :user_auth_tokens, dependent: :destroy
|
||||
|
||||
has_many :group_users, dependent: :destroy
|
||||
has_many :groups, through: :group_users
|
||||
has_many :secure_categories, through: :groups, source: :categories
|
||||
|
||||
has_many :user_emails, dependent: :destroy
|
||||
|
||||
has_one :primary_email, -> { where(primary: true) }, class_name: 'UserEmail', dependent: :destroy
|
||||
|
@ -69,10 +74,6 @@ class User < ActiveRecord::Base
|
|||
belongs_to :approved_by, class_name: 'User'
|
||||
belongs_to :primary_group, class_name: 'Group'
|
||||
|
||||
has_many :group_users, dependent: :destroy
|
||||
has_many :groups, through: :group_users
|
||||
has_many :secure_categories, through: :groups, source: :categories
|
||||
|
||||
has_many :muted_user_records, class_name: 'MutedUser'
|
||||
has_many :muted_users, through: :muted_user_records
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ require 'rails_helper'
|
|||
require_dependency 'user_destroyer'
|
||||
|
||||
describe UserDestroyer do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
describe 'new' do
|
||||
it 'raises an error when user is nil' do
|
||||
expect { UserDestroyer.new(nil) }.to raise_error(Discourse::InvalidParameters)
|
||||
|
@ -74,8 +78,6 @@ describe UserDestroyer do
|
|||
end
|
||||
|
||||
context "with a queued post" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let!(:qp) { Fabricate(:queued_post, user: user) }
|
||||
|
||||
it "removes the queued post" do
|
||||
|
@ -85,8 +87,6 @@ describe UserDestroyer do
|
|||
end
|
||||
|
||||
context "with a directory item record" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
|
||||
it "removes the directory item" do
|
||||
DirectoryItem.create!(
|
||||
|
@ -104,8 +104,6 @@ describe UserDestroyer do
|
|||
end
|
||||
|
||||
context "with a draft" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
let!(:draft) { Draft.set(user, 'test', 1, 'test') }
|
||||
|
||||
it "removed the draft" do
|
||||
|
@ -319,7 +317,6 @@ describe UserDestroyer do
|
|||
end
|
||||
|
||||
context 'user got an email' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let!(:email_log) { Fabricate(:email_log, user: user) }
|
||||
|
||||
it "deletes the email log" do
|
||||
|
@ -343,6 +340,21 @@ describe UserDestroyer do
|
|||
expect(@post.reload.like_count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'user belongs to groups that grant trust level' do
|
||||
let(:group) { Fabricate(:group, grant_trust_level: 2) }
|
||||
|
||||
before do
|
||||
group.add(user)
|
||||
end
|
||||
|
||||
it 'can delete the user' do
|
||||
d = UserDestroyer.new(admin)
|
||||
expect {
|
||||
d.destroy(user)
|
||||
}.to change { User.count }.by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue