Skip to content

Commit

Permalink
Follow up 34ec90b - Fixes #4243 - Add migration to fix existing roles…
Browse files Browse the repository at this point in the history
… without ticket.agent permission but group relations.
  • Loading branch information
rolfschmidt committed Sep 22, 2022
1 parent c73fa7c commit a6102e7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions db/migrate/20220922090123_issue4243_permission_fix.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/

class Issue4243PermissionFix < ActiveRecord::Migration[6.1]
def change
# return if it's a new setup
return if !Setting.exists?(name: 'system_init_done')

Role.find_each do |role|
next if role.groups.blank?

role.permissions |= Permission.where(name: 'ticket.agent')
end
end
end
21 changes: 21 additions & 0 deletions spec/db/migrate/issue_4243_permission_fix_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe Issue4243PermissionFix, type: :db_migration do
let!(:test_role) do
role = create(:role)
role.group_names_access_map = {
Group.first.name => 'full',
}
role
end

before do
migrate
end

it 'does add the permission if groups are present but ticket.agent permission is not set' do
expect(test_role.reload.permissions).to include(Permission.find_by(name: 'ticket.agent'))
end
end

0 comments on commit a6102e7

Please sign in to comment.