Skip to content

Commit

Permalink
Merge pull request #719 from datacite/optional-event-facets
Browse files Browse the repository at this point in the history
Make facets for v3 events API opt-in
  • Loading branch information
Martin Fenner authored Mar 10, 2021
2 parents 11bbc56 + f8eea89 commit e72488a
Show file tree
Hide file tree
Showing 22 changed files with 9,325 additions and 95 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Pull request
on:
pull_request:
branches:
- master
jobs:
test:
runs-on: ubuntu-latest
services:
memcached:
image: memcached:1.4.31
ports:
- 11211/udp
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: datacite
MYSQL_USER: root
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
ports:
- 3306
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
env:
discovery.type: single-node
ES_JAVA_OPTS: -Xms512m -Xmx512m
ELASTIC_PASSWORD: changeme
xpack.security.enabled: "false"
http.cors.enabled: "true"
http.cors.allow-origin: "*"
ports:
- 9200
env:
MEMCACHE_SERVERS: "localhost:11211"
MYSQL_HOST: "127.0.0.1"
MYSQL_DATABASE: datacite
MYSQL_USER: root
ES_HOST: "localhost:9200"
ELASTIC_PASSWORD: "changeme"
SECRET_KEY_BASE: ${{ secrets.SECRET_KEY_BASE }}
SESSION_ENCRYPTED_COOKIE_SALT: ${{ secrets.SESSION_ENCRYPTED_COOKIE_SALT }}
JWT_PRIVATE_KEY: ${{ secrets.JWT_PRIVATE_KEY }}
JWT_PUBLIC_KEY: ${{ secrets.JWT_PUBLIC_KEY }}
MDS_USERNAME: ${{ secrets.MDS_USERNAME }}
MDS_PASSWORD: ${{ secrets.MDS_PASSWORD }}
AWS_REGION: ${{ secrets.AWS_REGION }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
ruby-version: '2.6.x'
- uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
run: |
cp .env.build .env
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
sudo /etc/init.d/mysql start
bundle exec rails db:setup RAILS_ENV=test
- name: Lint and Test
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
ES_HOST: localhost:${{ job.services.elasticsearch.ports[9200] }}
ELASTIC_PASSWORD: "changeme"
MEMCACHE_SERVERS: "localhost:11211"
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
bundle exec rubocop
bundle exec rspec
echo $?
16 changes: 10 additions & 6 deletions app/controllers/v3/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ def index
publication_year: params[:publication_year],
occurred_at: params[:occurred_at],
year_month: params[:year_month],
aggregations: params[:aggregations],
unique: params[:unique],
state_event: params[:state],
scroll_id: params[:scroll_id],
facet: params[:facet],
page: page,
sort: sort,
)
Expand Down Expand Up @@ -177,28 +177,32 @@ def index
render json: V3::EventSerializer.new(results, options).serialized_json,
status: :ok
else
# parse "facet" query parameter to decide which facets should be shown
# by default no facets are shown
facets = Array.wrap(params[:facet].to_s.split(","))

sources =
if total.positive?
if total.positive? && facets.include?("sources")
facet_by_source(response.response.aggregations.sources.buckets)
end
prefixes =
if total.positive?
if total.positive? && facets.include?("prefixes")
facet_by_source(response.response.aggregations.prefixes.buckets)
end
citation_types =
if total.positive?
if total.positive? && facets.include?("citation_types")
facet_by_citation_type(
response.response.aggregations.citation_types.buckets,
)
end
relation_types =
if total.positive?
if total.positive? && facets.include?("relation_types")
facet_by_relation_type(
response.response.aggregations.relation_types.buckets,
)
end
registrants =
if total.positive?
if total.positive? && facets.include?("registrants")
facet_by_registrants(
response.response.aggregations.registrants.buckets,
)
Expand Down
86 changes: 0 additions & 86 deletions app/controllers/v3/sessions_controller.rb

This file was deleted.

1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
resources :activities
resources :events
end
resources :events
resources :prefixes, constraints: { id: /.+/ }
resources :provider_prefixes, path: "provider-prefixes"
resources :random, only: %i[index]
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
provider

uid { SecureRandom.uuid }
email { "[email protected]" }
sequence(:email) { |n| "josiah#{n}@example.org" }
given_name { "Josiah" }
family_name { "Carberry" }
role_name { ["voting"] }
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@

attributes = json.dig("data", 1, "attributes")
expect(attributes["name"]).to eq("Josiah Carberry")
expect(attributes["email"]).to eq("josiah@example.org")
expect(attributes["email"]).to start_with("josiah")
expect(attributes["roleName"]).to eq(["billing"])

relationships = json.dig("data", 1, "relationships")
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/exports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
"uid,fabricaAccountId,fabricaId,email,firstName,lastName,type,createdAt,modifiedAt,deletedAt,isActive\n",
)
expect(csv[1]).to start_with(
"#{contact.uid},UVA,UVA-[email protected],[email protected],Josiah,Carberry,voting",
"#{contact.uid},UVA,UVA-#{contact.email},#{contact.email},Josiah,Carberry,voting",
)
end
end
Expand Down
Loading

0 comments on commit e72488a

Please sign in to comment.