From 41bb2e07fb05ee62b9f0557ac349264a4b246586 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 20 Jan 2025 15:17:56 +0100 Subject: [PATCH 1/5] Add user endpoint --- app/controllers/api/v1/users_controller.rb | 7 +++ config/routes.rb | 1 + spec/requests/api/v1/users_spec.rb | 18 ++++++ spec/swagger/api/v1/users_controller_spec.rb | 64 ++++++++++++++++++++ swagger/v1/swagger.yaml | 17 ++++++ 5 files changed, 107 insertions(+) create mode 100644 app/controllers/api/v1/users_controller.rb create mode 100644 spec/requests/api/v1/users_spec.rb create mode 100644 spec/swagger/api/v1/users_controller_spec.rb diff --git a/app/controllers/api/v1/users_controller.rb b/app/controllers/api/v1/users_controller.rb new file mode 100644 index 00000000..4fbb3f60 --- /dev/null +++ b/app/controllers/api/v1/users_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Api::V1::UsersController < ApiController + def me + render json: { user: current_api_user } + end +end diff --git a/config/routes.rb b/config/routes.rb index 0befcca4..862ae6c4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -65,6 +65,7 @@ Rails.application.routes.draw do get 'health', to: 'health#index' patch 'settings', to: 'settings#update' get 'settings', to: 'settings#index' + get 'users/me', to: 'users#me' resources :areas, only: %i[index create update destroy] resources :points, only: %i[index destroy update] diff --git a/spec/requests/api/v1/users_spec.rb b/spec/requests/api/v1/users_spec.rb new file mode 100644 index 00000000..3075a94f --- /dev/null +++ b/spec/requests/api/v1/users_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Api::V1::Users', type: :request do + describe 'GET /me' do + let(:user) { create(:user) } + let(:headers) { { 'Authorization' => "Bearer #{user.api_key}" } } + + it 'returns http success' do + get '/api/v1/users/me', headers: headers + + expect(response).to have_http_status(:success) + expect(response.body).to include(user.email) + expect(response.body).to include(user.id.to_s) + end + end +end diff --git a/spec/swagger/api/v1/users_controller_spec.rb b/spec/swagger/api/v1/users_controller_spec.rb new file mode 100644 index 00000000..753f4f08 --- /dev/null +++ b/spec/swagger/api/v1/users_controller_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'swagger_helper' + +describe 'Users API', type: :request do + path '/api/v1/users/me' do + get 'Returns the current user' do + tags 'Users' + consumes 'application/json' + security [bearer_auth: []] + parameter name: 'Authorization', in: :header, type: :string, required: true, + description: 'Bearer token in the format: Bearer {api_key}' + + response '200', 'user found' do + let(:user) { create(:user) } + let(:Authorization) { "Bearer #{user.api_key}" } + + schema type: :object, + properties: { + user: { + type: :object, + properties: { + id: { type: :integer }, + email: { type: :string }, + created_at: { type: :string, format: 'date-time' }, + updated_at: { type: :string, format: 'date-time' }, + api_key: { type: :string }, + theme: { type: :string }, + settings: { + type: :object, + properties: { + immich_url: { type: :string }, + route_opacity: { type: :string }, + immich_api_key: { type: :string }, + live_map_enabled: { type: :boolean }, + fog_of_war_meters: { type: :string }, + preferred_map_layer: { type: :string }, + speed_colored_routes: { type: :boolean }, + meters_between_routes: { type: :string }, + points_rendering_mode: { type: :string }, + minutes_between_routes: { type: :string }, + time_threshold_minutes: { type: :string }, + merge_threshold_minutes: { type: :string }, + speed_colored_polylines: { type: :boolean } + } + }, + admin: { type: :boolean } + } + } + } + + after do |example| + example.metadata[:response][:content] = { + 'application/json' => { + example: JSON.parse(response.body) + } + } + end + + run_test! + end + end + end +end diff --git a/swagger/v1/swagger.yaml b/swagger/v1/swagger.yaml index beed0840..3093df05 100644 --- a/swagger/v1/swagger.yaml +++ b/swagger/v1/swagger.yaml @@ -892,6 +892,23 @@ paths: - totalCountriesVisited - totalCitiesVisited - yearlyStats + "/api/v1/users/me": + get: + summary: Returns the current user + tags: + - Users + security: + - bearer_auth: [] + parameters: + - name: Authorization + in: header + required: true + description: 'Bearer token in the format: Bearer {api_key}' + schema: + type: string + responses: + '200': + description: user found servers: - url: http://{defaultHost} variables: From bb600230a7917bade9b93f712dddc9c9faf0ac0e Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 20 Jan 2025 15:18:40 +0100 Subject: [PATCH 2/5] Update changelog and app version --- .app_version | 2 +- CHANGELOG.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.app_version b/.app_version index 4240544f..03035cdd 100644 --- a/.app_version +++ b/.app_version @@ -1 +1 @@ -0.22.4 +0.22.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index ecc13f47..35abea81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +# 0.22.5 - 2025-01-20 + +### Added + +- `GET /api/v1/users/me` endpoint added to get current user. + # 0.22.4 - 2025-01-20 ### Added From bb139624f7a0bc63419ee0c3972ee6b383c2e2d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:56:47 +0000 Subject: [PATCH 3/5] Bump rubocop-rails from 2.28.0 to 2.29.0 Bumps [rubocop-rails](https://github.com/rubocop/rubocop-rails) from 2.28.0 to 2.29.0. - [Release notes](https://github.com/rubocop/rubocop-rails/releases) - [Changelog](https://github.com/rubocop/rubocop-rails/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop-rails/compare/v2.28.0...v2.29.0) --- updated-dependencies: - dependency-name: rubocop-rails dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 128bf38f..5d0e389d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,7 @@ GEM byebug (11.1.3) chartkick (5.1.2) coderay (1.1.3) - concurrent-ruby (1.3.4) + concurrent-ruby (1.3.5) connection_pool (2.5.0) content_disposition (1.0.0) crack (1.0.0) @@ -154,7 +154,7 @@ GEM csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) importmap-rails (2.1.0) actionpack (>= 6.0.0) @@ -232,7 +232,7 @@ GEM orm_adapter (0.5.0) ostruct (0.6.1) parallel (1.26.3) - parser (3.3.6.0) + parser (3.3.7.0) ast (~> 2.4.1) racc patience_diff (1.2.0) @@ -340,7 +340,7 @@ GEM rswag-ui (2.16.0) actionpack (>= 5.2, < 8.1) railties (>= 5.2, < 8.1) - rubocop (1.69.2) + rubocop (1.70.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -352,7 +352,7 @@ GEM unicode-display_width (>= 2.4.0, < 4.0) rubocop-ast (1.37.0) parser (>= 3.3.1.0) - rubocop-rails (2.28.0) + rubocop-rails (2.29.0) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.52.0, < 2.0) @@ -413,7 +413,7 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode (0.4.4.5) - unicode-display_width (3.1.3) + unicode-display_width (3.1.4) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) uri (1.0.2) From f558e3d4b16f57f308a6abdc7618667c7b7c8613 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:57:28 +0000 Subject: [PATCH 4/5] Bump tailwindcss-rails from 3.2.0 to 3.3.0 Bumps [tailwindcss-rails](https://github.com/rails/tailwindcss-rails) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/rails/tailwindcss-rails/releases) - [Changelog](https://github.com/rails/tailwindcss-rails/blob/main/CHANGELOG.md) - [Commits](https://github.com/rails/tailwindcss-rails/compare/v3.2.0...v3.3.0) --- updated-dependencies: - dependency-name: tailwindcss-rails dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 128bf38f..3b1d7f62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,7 @@ GEM byebug (11.1.3) chartkick (5.1.2) coderay (1.1.3) - concurrent-ruby (1.3.4) + concurrent-ruby (1.3.5) connection_pool (2.5.0) content_disposition (1.0.0) crack (1.0.0) @@ -154,7 +154,7 @@ GEM csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) importmap-rails (2.1.0) actionpack (>= 6.0.0) @@ -212,18 +212,18 @@ GEM net-smtp (0.5.0) net-protocol nio4r (2.7.4) - nokogiri (1.18.1) + nokogiri (1.18.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.1-aarch64-linux-gnu) + nokogiri (1.18.2-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.1-arm-linux-gnu) + nokogiri (1.18.2-arm-linux-gnu) racc (~> 1.4) - nokogiri (1.18.1-arm64-darwin) + nokogiri (1.18.2-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.1-x86_64-darwin) + nokogiri (1.18.2-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.1-x86_64-linux-gnu) + nokogiri (1.18.2-x86_64-linux-gnu) racc (~> 1.4) oj (3.16.9) bigdecimal (>= 3.0) @@ -248,7 +248,7 @@ GEM pry (>= 0.13, < 0.15) pry-rails (0.3.11) pry (>= 0.13.0) - psych (5.2.2) + psych (5.2.3) date stringio public_suffix (6.0.1) @@ -297,7 +297,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.2.1) - rdoc (6.10.0) + rdoc (6.11.0) psych (>= 4.0.0) redis (5.3.0) redis-client (>= 0.22.0) @@ -396,7 +396,7 @@ GEM attr_extras (>= 6.2.4) diff-lcs patience_diff - tailwindcss-rails (3.2.0) + tailwindcss-rails (3.3.0) railties (>= 7.0.0) tailwindcss-ruby tailwindcss-ruby (3.4.17) From d549a31a0a7f8042a83d3f9de29e48a66fd5ec71 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:57:39 +0000 Subject: [PATCH 5/5] Bump sidekiq-cron from 2.0.1 to 2.1.0 Bumps [sidekiq-cron](https://github.com/ondrejbartas/sidekiq-cron) from 2.0.1 to 2.1.0. - [Release notes](https://github.com/ondrejbartas/sidekiq-cron/releases) - [Changelog](https://github.com/sidekiq-cron/sidekiq-cron/blob/master/CHANGELOG.md) - [Commits](https://github.com/ondrejbartas/sidekiq-cron/compare/v2.0.1...v2.1.0) --- updated-dependencies: - dependency-name: sidekiq-cron dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Gemfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 128bf38f..3f00534f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -95,7 +95,7 @@ GEM byebug (11.1.3) chartkick (5.1.2) coderay (1.1.3) - concurrent-ruby (1.3.4) + concurrent-ruby (1.3.5) connection_pool (2.5.0) content_disposition (1.0.0) crack (1.0.0) @@ -154,7 +154,7 @@ GEM csv mini_mime (>= 1.0.0) multi_xml (>= 0.5.2) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) importmap-rails (2.1.0) actionpack (>= 6.0.0) @@ -301,7 +301,7 @@ GEM psych (>= 4.0.0) redis (5.3.0) redis-client (>= 0.22.0) - redis-client (0.23.0) + redis-client (0.23.2) connection_pool regexp_parser (2.10.0) reline (0.6.0) @@ -369,7 +369,7 @@ GEM logger rack (>= 2.2.4) redis-client (>= 0.22.2) - sidekiq-cron (2.0.1) + sidekiq-cron (2.1.0) cronex (>= 0.13.0) fugit (~> 1.8, >= 1.11.1) globalid (>= 1.0.1)