Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to destroy all users dashboards #18555

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/miq_widget_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def destroy_user_versions
MiqWidgetSet.with_users.where(:name => name, :group_id => owner_id).destroy_all
end

def self.destroy_user_versions
MiqWidgetSet.with_users.destroy_all
end

def self.where_unique_on(name, user = nil)
userid = user.try(:userid)
group_id = user.try(:current_group_id)
Expand Down
13 changes: 13 additions & 0 deletions spec/models/miq_widget_set_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@
end
end

describe ".destroy_user_versions" do
before do
FactoryBot.create(:miq_widget_set, :name => 'User_Home', :userid => user.userid)
end

it "destroys all user's versions of dashboards (dashboards been customized by user)" do
expect(MiqWidgetSet.count).to eq(2)
MiqWidgetSet.destroy_user_versions
expect(MiqWidgetSet.count).to eq(1)
expect(MiqWidgetSet.first).to eq(@ws_group)
end
end

describe "#where_unique_on" do
let(:group2) { FactoryBot.create(:miq_group, :description => 'dev group2') }
let(:ws_1) { FactoryBot.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) }
Expand Down