Skip to content

Commit

Permalink
don't export scorer details, just the name
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Nov 28, 2023
1 parent 56b5d58 commit ef0a89f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
5 changes: 2 additions & 3 deletions app/controllers/api/v1/import/cases_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def create

@case = Case.new

list_of_emails_of_users << params_to_use[:owner_email]

scorer_name = params_to_use[:scorer][:name]
unless Scorer.exists?(name: scorer_name)
@case.errors.add(:scorer, "Scorer with name '#{scorer_name}' needs to be migrated over first.")
Expand Down Expand Up @@ -47,7 +45,8 @@ def create

@case.scorer = Scorer.find_by(name: scorer_name)

@case.owner = User.find_by(email: params_to_use[:owner_email])
# Force the imported case to be owned by the user doing the importing. Otherwise you can loose the case!
@case.owner = User.find_by(email: current_user.email)

# For some reason we can't do @case.queries.build with out forcing a save.
# Works fine with book however.
Expand Down
23 changes: 12 additions & 11 deletions app/views/api/v1/scorers/_scorer.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

export ||= false

json.scorer_id scorer.id unless export
json.communal scorer.communal
json.code scorer.code
json.name scorer.name
json.scale scorer.scale
json.owner_id scorer.owner_id unless export
json.owned scorer.owner_id == current_user.id
json.owner_name scorer.owner.name if scorer.owner.present?
json.show_scale_labels scorer.show_scale_labels
json.scale_with_labels scorer.scale_with_labels
json.name scorer.name

unless export
json.scorer_id scorer.id
json.communal scorer.communal
json.code scorer.code
json.scale scorer.scale
json.owner_id scorer.owner_id unless export
json.owned scorer.owner_id == current_user.id
json.owner_name scorer.owner.name if scorer.owner.present?
json.show_scale_labels scorer.show_scale_labels
json.scale_with_labels scorer.scale_with_labels

if export
teams = scorer.teams.find_all { |t| current_user.teams.all.include?(t) }
json.teams teams do |team|
json.id team.id
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/api/v1/case_scorers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class CaseScorersControllerTest < ActionController::TestCase
data = response.parsed_body

expected_response = {
'name' => scorer.name,
'scorer_id' => scorer.id,
'communal' => scorer.communal,
'code' => scorer.code,
'name' => scorer.name,
'scale' => scorer.scale,
'owner_id' => scorer.owner_id,
'owned' => false,
'owner_name' => scorer.owner.name,
'show_scale_labels' => scorer.show_scale_labels,
'scale_with_labels' => scorer.scale_with_labels,
'teams' => [],
}

assert_equal expected_response, data['default']
Expand Down
2 changes: 2 additions & 0 deletions test/controllers/api/v1/export/cases_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CasesControllerTest < ActionController::TestCase
assert_nil body['scorer_id']
assert_not_nil body['scorer']
assert_nil body['scorer']['scorer_id']
assert_nil body['scorer']['code']
assert_nil body['scorer']['teams']

assert_not_nil body['try']
assert_not_empty body['try']['curator_variables']
Expand Down
8 changes: 6 additions & 2 deletions test/controllers/api/v1/scorers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class ScorersControllerTest < ActionController::TestCase
let(:owned_scorer) { scorers(:owned_scorer) }
let(:shared_scorer) { scorers(:shared_scorer) }
let(:communal_scorer) { scorers(:quepid_default_scorer) }
let(:shared_team) { teams(:shared) }

test 'returns all scorers owned by user and those shared through teams' do
get :index
Expand All @@ -530,29 +531,32 @@ class ScorersControllerTest < ActionController::TestCase
scorers = response.parsed_body

expected_owned_response = {
'name' => owned_scorer.name,
'scorer_id' => owned_scorer.id,
'communal' => owned_scorer.communal,
'code' => owned_scorer.code,
'name' => owned_scorer.name,
'scale' => owned_scorer.scale,
'owner_id' => owned_scorer.owner_id,
'owned' => true,
'owner_name' => owned_scorer.owner.name,
'show_scale_labels' => false,
'scale_with_labels' => nil,
'teams' => [],
}

expected_shared_response = {
'name' => shared_scorer.name,
'scorer_id' => shared_scorer.id,
'communal' => owned_scorer.communal,
'code' => shared_scorer.code,
'name' => shared_scorer.name,
'scale' => shared_scorer.scale,
'owner_id' => shared_scorer.owner_id,
'owned' => false,
'owner_name' => shared_scorer.owner.name,
'show_scale_labels' => false,
'scale_with_labels' => nil,
'teams' => [ { 'id' => shared_team.id, 'name' => shared_team.name,
'owner_id' => shared_team.owner_id } ],
}

assert_includes scorers['user_scorers'], expected_owned_response
Expand Down

0 comments on commit ef0a89f

Please sign in to comment.