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

remove server side language content loading #3658

Merged
merged 1 commit into from
Sep 16, 2021
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
29 changes: 0 additions & 29 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'accept_language_extractor'

module Api
include ApiErrors

Expand Down Expand Up @@ -75,24 +73,6 @@ def api_user
@api_user ||= ApiUser.new(current_resource_owner, admin: admin_flag?)
end

def current_languages
param_langs = [ params[:language] ]
user_langs = user_accept_languages
header_langs = parse_http_accept_languages
( param_langs | user_langs | header_langs ).compact
end

def user_accept_languages
api_user.try(:languages) || []
end

def parse_http_accept_languages
language_extractor = AcceptLanguageExtractor
.new(request.env['HTTP_ACCEPT_LANGUAGE'])

language_extractor.parse_languages
end

def request_ip
request.remote_ip
end
Expand All @@ -119,14 +99,5 @@ def ban_user
end
end
end

def context
case action_name
when "show", "index"
{ languages: current_languages }
else
{ }
end
end
end
end
1 change: 0 additions & 1 deletion app/controllers/api/v1/workflows_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def context
case action_name
when "show", "index"
{
languages: current_languages,
published: params["published"]
}.merge(field_context)
else
Expand Down
31 changes: 0 additions & 31 deletions lib/accept_language_extractor.rb

This file was deleted.

26 changes: 0 additions & 26 deletions spec/controllers/api/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,6 @@ def index
end
end

describe "#current_language" do
controller do
def index
render json_api: current_languages
end
end

before(:each) do
user = create(:user, :languages)
default_request(user_id: user.id)
get :index, language: 'es'
end

it 'should include langauge param as the first language' do
expect(json_response.first).to eq('es')
end

it 'should include the user\'s default languages after the lang param' do
expect(json_response[1..-1]).to include('en', 'fr-ca')
end

it 'should include Accept-Language(s) after the user languages' do
expect(json_response[-3..-1]).to include('zh', 'zh-tw', 'fr-fr')
end
end

describe "when a banned user attempts to take an action" do
let(:user) { create(:user, banned: true) }

Expand Down
15 changes: 0 additions & 15 deletions spec/lib/accept_language_extractor_spec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion spec/serializers/organization_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe OrganizationSerializer do
let(:organization) { create(:organization) }
let(:context) { {languages: ['en'], fields: [:title]} }
let(:context) { { fields: [:title] } }

let(:serializer) do
s = OrganizationSerializer.new
Expand Down
2 changes: 1 addition & 1 deletion spec/serializers/project_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ProjectSerializer do
let(:project) { create(:full_project, state: "finished", live: false) }
let(:context) { {languages: ['en'], fields: [:title, :url_labels]} }
let(:context) { { fields: %i[title url_labels] } }

let(:serializer) do
s = ProjectSerializer.new
Expand Down
5 changes: 2 additions & 3 deletions spec/serializers/workflow_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
let(:serializer) do
serializer = WorkflowSerializer.new
serializer.instance_variable_set(:@model, workflow)
serializer.instance_variable_set(:@context,
{languages: ['en']})
serializer.instance_variable_set(:@context, {})
serializer
end

Expand Down Expand Up @@ -36,7 +35,7 @@
workflow.strings["interest.question"] = "Draw a round thing"
workflow.save!

serializer.instance_variable_set(:@context, {languages: ['en'], published: true})
serializer.instance_variable_set(:@context, { published: true })
expect(serializer.tasks['interest']['question']).to eq('Draw a circle')
end
end
Expand Down
6 changes: 0 additions & 6 deletions spec/support/api_request_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ def set_content_type
request.env["CONTENT_TYPE"] = "application/json"
end

def set_accept_language
request.env['HTTP_ACCEPT_LANGUAGE'] = 'en, zh;q=0.9, zh-tw;q=0.8, fr-fr;q=0.6'
end

def set_patch_content_type
request.headers["Content-Type"] = "application/json-patch"
end
Expand Down Expand Up @@ -89,15 +85,13 @@ def stub_content_filter
def default_request(scopes: ["public"], user_id: nil)
set_accept
set_content_type
set_accept_language
set_preconditions
stub_content_filter
stub_token(scopes: scopes, user_id: user_id)
end

def unauthenticated_request
set_accept
set_accept_language
set_preconditions
stub_content_filter
stub_token
Expand Down
12 changes: 0 additions & 12 deletions spec/support/locale_format.rb

This file was deleted.