Skip to content

Commit

Permalink
Fix newly created user is not added into global-viewer group (#247)
Browse files Browse the repository at this point in the history
* Fix newly created user is not added into global-viewer group despite having the appropriate ENV

* add role_id validation for GroupUser and fix add_global_viewer_group spec for User model

Co-authored-by: Beni Budiharto <[email protected]>

Co-authored-by: Rayhan Gusty Alif <[email protected]>
Co-authored-by: Beni Budiharto <[email protected]>
  • Loading branch information
3 people authored Jul 18, 2022
1 parent a2d3cd6 commit 40c2f4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def self.valid_email_domain? email

def add_global_viewer_group
group = Group.find_by(name: Figaro.env.global_viewer_role)
group_role = AppGroupRole.find_by_name('member')
group_user = GroupUser.create(
group_id: group.id,
user_id: self.id
user_id: self.id,
role_id: group_role.id
)
end

Expand Down
11 changes: 9 additions & 2 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
require 'faker'

RSpec.describe User, type: :model do
if Figaro.env.global_viewer == "true"
before(:each) do
create(:group, name: Figaro.env.global_viewer_role)
@role = create(:app_group_role)
end
end

describe '#self.find_by_username_or_email' do
before(:each) do
@user = create(:user, username: 'test_user', email: '[email protected]')
Expand Down Expand Up @@ -99,7 +106,7 @@
let!(:app_group) { create(:app_group) }

it 'should filter out unassociated app group' do
app_groups = user.filter_accessible_app_groups(AppGroup.all)
app_groups = user.filter_accessible_app_groups(AppGroup.all, roles: @role)
expect(app_groups.exists?).to be false
end

Expand Down Expand Up @@ -173,7 +180,7 @@
let!(:group) { create(:group) }

it 'should filter out unassociated app group' do
groups = user.filter_accessible_user_groups(Group.all)
groups = user.filter_accessible_user_groups(Group.all, roles: @role)
expect(groups.exists?).to be false
end

Expand Down

0 comments on commit 40c2f4c

Please sign in to comment.