From 7066aae754c00bb6f5ce275c9be1c66ff7fea17d Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 4 Mar 2024 09:15:04 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Change:=20=E4=B8=80=E8=88=AC=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AF=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E3=81=A7=E6=8B=9B=E5=BE=85=E3=82=92=E4=B8=8D?= =?UTF-8?q?=E5=8F=AF=E3=81=AB=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user_role.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user_role.rb b/app/models/user_role.rb index 75145fb2bd80f7..7859eef3069a45 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -46,7 +46,7 @@ module Flags NONE = 0 ALL = FLAGS.values.reduce(&:|) - DEFAULT = FLAGS[:invite_users] + DEFAULT = 0 CATEGORIES = { invites: %i( From ec0d51334fad2a689f38f89d28b4fa72e91e6feb Mon Sep 17 00:00:00 2001 From: KMY Date: Mon, 4 Mar 2024 10:17:00 +0900 Subject: [PATCH 2/2] Fix test --- app/models/user_role.rb | 3 ++- config/roles.yml | 1 + spec/models/user_role_spec.rb | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/user_role.rb b/app/models/user_role.rb index 7859eef3069a45..6077bd49507f5b 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -47,6 +47,7 @@ module Flags ALL = FLAGS.values.reduce(&:|) DEFAULT = 0 + EVERYONE_ALLOWED = FLAGS[:invite_users] CATEGORIES = { invites: %i( @@ -196,6 +197,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 diff --git a/config/roles.yml b/config/roles.yml index f443250d177f76..0439c9f741d5aa 100644 --- a/config/roles.yml +++ b/config/roles.yml @@ -28,6 +28,7 @@ admin: - manage_custom_emojis - manage_webhooks - manage_roles + - invite_users owner: name: Owner position: 1000 diff --git a/spec/models/user_role_spec.rb b/spec/models/user_role_spec.rb index 9dd04a8172e424..06fb693def6c70 100644 --- a/spec/models/user_role_spec.rb +++ b/spec/models/user_role_spec.rb @@ -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(-1) 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