Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintenance: Provide allow_signup column to define the signup permiss…
…ions for roles and disable new permissions by default as signup permission.
- Loading branch information
1 parent
5e94f78
commit f0462d4
Showing
5 changed files
with
116 additions
and
44 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
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
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,31 @@ | ||
class RoleSignupColumn < ActiveRecord::Migration[5.2] | ||
def change | ||
|
||
# return if it's a new setup | ||
return if !Setting.exists?(name: 'system_init_done') | ||
|
||
add_column :permissions, :allow_signup, :boolean, null: false, default: false | ||
|
||
signup_permissions = [ | ||
'user_preferences', | ||
'user_preferences.password', | ||
'user_preferences.notifications', | ||
'user_preferences.access_token', | ||
'user_preferences.language', | ||
'user_preferences.linked_accounts', | ||
'user_preferences.device', | ||
'user_preferences.avatar', | ||
'user_preferences.calendar', | ||
'user_preferences.out_of_office', | ||
'ticket.customer', | ||
] | ||
|
||
Permission.where(name: signup_permissions).update(allow_signup: true) | ||
|
||
Role.where(default_at_signup: true).find_each do |role| | ||
role.permissions.where.not(name: signup_permissions).find_each do |permission| | ||
role.permission_revoke(permission.name) | ||
end | ||
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
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,30 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe RoleSignupColumn, type: :db_migration, db_strategy: :reset do | ||
context 'when a role contains signup permissions' do | ||
let!(:role) do | ||
role = create(:role) | ||
role.permission_grant('user_preferences.password') | ||
role.permission_grant('ticket.agent') | ||
role.update_column(:default_at_signup, true) | ||
role | ||
end | ||
|
||
before do | ||
without_column(:permissions, column: :allow_signup) | ||
migrate | ||
end | ||
|
||
it 'has password permission' do | ||
expect(role.reload.permissions.map(&:name)).to include('user_preferences.password') | ||
end | ||
|
||
it 'has no agent permission' do | ||
expect(role.reload.permissions.map(&:name)).not_to include('ticket.agent') | ||
end | ||
|
||
it 'has permission with allow_signup set correctly' do | ||
expect(Permission.find_by(name: 'user_preferences.password').allow_signup).to be true | ||
end | ||
end | ||
end |