Skip to content

Commit

Permalink
Change: 一般ユーザーはデフォルトで招待を不可にするよう変更 (#629)
Browse files Browse the repository at this point in the history
* Change: 一般ユーザーはデフォルトで招待を不可にするよう変更

* Fix test
  • Loading branch information
kmycode authored Mar 4, 2024
1 parent 878b4eb commit 4119b87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/models/user_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ module Flags
NONE = 0
ALL = FLAGS.values.reduce(&:|)

DEFAULT = FLAGS[:invite_users]
DEFAULT = 0
EVERYONE_ALLOWED = FLAGS[:invite_users]

CATEGORIES = {
invites: %i(
Expand Down Expand Up @@ -197,6 +198,6 @@ def validate_position_elevation
end

def validate_dangerous_permissions
errors.add(:permissions_as_keys, :dangerous) if everyone? && Flags::DEFAULT & permissions != permissions
errors.add(:permissions_as_keys, :dangerous) if everyone? && Flags::EVERYONE_ALLOWED & permissions != permissions
end
end
1 change: 1 addition & 0 deletions config/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ admin:
- manage_custom_emojis
- manage_webhooks
- manage_roles
- invite_users
owner:
name: Owner
position: 1000
Expand Down
6 changes: 5 additions & 1 deletion spec/models/user_role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@
end

it 'has default permissions' do
expect(subject.permissions).to eq UserRole::FLAGS[:invite_users]
expect(subject.permissions).to eq 0
end

it 'has negative position' do
expect(subject.position).to eq(described_class::NOBODY_POSITION)
end

it 'is able to add invite permission' do
expect { subject.update!(permissions: UserRole::FLAGS[:invite_users]) }.to_not raise_error
end
end

describe '.nobody' do
Expand Down

0 comments on commit 4119b87

Please sign in to comment.