forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…t permission. Co-authored-by: Florian Liebe <[email protected]>
- Loading branch information
1 parent
1bd8194
commit 5599657
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
class Issue5083ChatPermission < ActiveRecord::Migration[7.0] | ||
def change | ||
# return if it's a new setup | ||
return if !Setting.exists?(name: 'system_init_done') | ||
|
||
parent_chat_permission = Permission.find_by(name: 'chat') | ||
chat_permissions = Permission.where("name LIKE 'chat.%'") | ||
|
||
Role.find_each do |role| | ||
next if role.permissions.exclude?(parent_chat_permission) | ||
|
||
role.permissions -= [parent_chat_permission] | ||
role.permissions += chat_permissions | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Issue5083ChatPermission, type: :db_migration do | ||
let(:role_with_chat_permission) { create(:role) } | ||
let(:role_without_chat_permission) { create(:role) } | ||
|
||
before do | ||
|
||
# undisable chat permission | ||
Permission.create_or_update( | ||
name: 'chat', | ||
note: __('Access to %s'), | ||
preferences: { | ||
translations: [__('Chat')], | ||
}, | ||
) | ||
|
||
role_with_chat_permission.permissions << Permission.find_by(name: 'chat') | ||
role_without_chat_permission | ||
|
||
# reset original state | ||
Permission.create_or_update( | ||
name: 'chat', | ||
note: __('Access to %s'), | ||
preferences: { | ||
translations: [__('Chat')], | ||
disabled: true, | ||
}, | ||
) | ||
|
||
migrate | ||
end | ||
|
||
it 'does migrate role with chat permission', :aggregate_failures do | ||
expect(role_with_chat_permission.reload.permissions).not_to include(Permission.find_by(name: 'chat')) | ||
expect(role_with_chat_permission.reload.permissions).to include(Permission.find_by(name: 'chat.agent')) | ||
end | ||
|
||
it 'does not touch role without chat permission', :aggregate_failures do | ||
expect(role_without_chat_permission.reload.permissions).not_to include(Permission.find_by(name: 'chat')) | ||
expect(role_without_chat_permission.reload.permissions).not_to include(Permission.find_by(name: 'chat.agent')) | ||
end | ||
end |