Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow zoo admins to view join token when querying user group #4338

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/serializers/user_group_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def type

def include_join_token?
return false unless current_user
@model.has_admin? current_user
current_user.is_admin? || @model.has_admin?(current_user)
end

def current_user
Expand Down
29 changes: 25 additions & 4 deletions spec/serializers/user_group_serializer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,39 @@
require "spec_helper"
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe UserGroupSerializer do
let(:user_group) { create(:user_group) }
let(:user) { create(:user) }

describe 'join token' do
it 'is serialized when the current user is a group admin' do
user = create(:user)
create(:membership, user: user, user_group: user_group, roles: ["group_admin"])
create(:membership, user: user, user_group: user_group, roles: ['group_admin'])

serialized = described_class.serialize(user_group, current_user: user)
expect(serialized[:user_groups][0][:join_token]).to eq(user_group.join_token)
end

it 'is not serialized otherwise' do
it 'is serialized when the current user is a zooniverse admin' do
admin_user = create(:user, admin: true)

serialized = described_class.serialize(user_group, current_user: admin_user)
expect(serialized[:user_groups][0][:join_token]).to eq(user_group.join_token)
end

it 'is not serialized when user is a group member' do
create(:membership, user: user, user_group: user_group, roles: ['group_member'])

serialized = described_class.serialize(user_group, current_user: user)
expect(serialized[:user_groups][0][:join_token]).to be_nil
end

it 'is not serialized for user not part of group' do
serialized = described_class.serialize(user_group, current_user: user)
expect(serialized[:user_groups][0][:join_token]).to be_nil
end

it 'is not serialized when there is no current_user' do
serialized = described_class.serialize(user_group)
expect(serialized[:user_groups][0][:join_token]).to be_nil
end
Expand Down
Loading