bullet_train-api 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aa6663e2cb44dcb5ee04f1523126af49e244a71168c4be2e4b5333ef957890f
4
- data.tar.gz: 6efa8a9d4538ff0a031fba1bbdd8dfa5fdef35f099be7e1045766cb760ca1fed
3
+ metadata.gz: ad13ea6c52199631e43bc3ef4367f886d64568faea6d88dd3f5f1857bb0416e2
4
+ data.tar.gz: 90deafe4bb3b6680f0ccaa79e715e66cfcadf247053c651badf489f4ab845e95
5
5
  SHA512:
6
- metadata.gz: 89cd48b2f9291e06563533ee36d7081176a82ffa97e7c62096477c5cfa97501f83b7f0d1f34bad3d52f22a2b910e75789a320c60e0196b0df4c7073045444a21
7
- data.tar.gz: c75051c39a212d6994a7b19ed4fb1df756927d5599c4d2b8e92330855b4cb08e1d7ff5a884902d793d6b878c1d37d77153db3dfa7173ff1f22801b3ff4f245e2
6
+ metadata.gz: a254ff4f0174985973a4ac4c1b28d4d6d20cc547633a34da3277393d46470485f623126f5560425b5e1e124a8832a360e9a4f9ab343a6d8704bb9669553edaed
7
+ data.tar.gz: 3a726a97a5070fdfbb092b6437e90c7019de0fd9a256bcffa035cbdcb5496ee5ac9e2212ef499297686fed843d2fba87cc47984c60199253ca685d1b96d91cfe
@@ -0,0 +1,69 @@
1
+ require "pagy_cursor/pagy/extras/cursor"
2
+ require "pagy_cursor/pagy/extras/uuid_cursor"
3
+
4
+ module Api::Controllers::Base
5
+ extend ActiveSupport::Concern
6
+
7
+ # TODO Why doesn't `before_action :doorkeeper_authorize!` throw an exception?
8
+ class NotAuthenticatedError < StandardError
9
+ end
10
+
11
+ included do
12
+ include ActionController::Helpers
13
+ helper ApplicationHelper
14
+
15
+ include LoadsAndAuthorizesResource
16
+ include Pagy::Backend
17
+
18
+ before_action :set_default_response_format
19
+ before_action :doorkeeper_authorize!
20
+
21
+ rescue_from CanCan::AccessDenied, ActiveRecord::RecordNotFound do |exception|
22
+ render json: {error: "Not found"}, status: :not_found
23
+ end
24
+
25
+ rescue_from NotAuthenticatedError do |exception|
26
+ render json: {error: "Invalid token"}, status: :unauthorized
27
+ end
28
+
29
+ before_action :apply_pagination, only: [:index]
30
+ end
31
+
32
+ def permitted_fields
33
+ []
34
+ end
35
+
36
+ def permitted_arrays
37
+ {}
38
+ end
39
+
40
+ def process_params(strong_params)
41
+ end
42
+
43
+ def current_user
44
+ raise NotAuthenticatedError unless doorkeeper_token.present?
45
+ @current_user ||= User.find_by(id: doorkeeper_token[:resource_owner_id])
46
+ end
47
+
48
+ def current_team
49
+ # Application agents are users but only have one team.
50
+ current_user&.teams&.first
51
+ end
52
+
53
+ def apply_pagination
54
+ collection_variable = "@#{self.class.name.split("::").last.gsub("Controller", "").underscore}"
55
+ collection = instance_variable_get collection_variable
56
+ @pagy, collection = pagy_cursor collection
57
+ instance_variable_set collection_variable, collection
58
+ end
59
+
60
+ def set_default_response_format
61
+ request.format = :json
62
+ end
63
+
64
+ class_methods do
65
+ def regex_to_remove_controller_namespace
66
+ /^#{name.split("::").first(2).join("::") + "::"}/
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,49 @@
1
+ module Api::V1::Teams::ControllerBase
2
+ extend ActiveSupport::Concern
3
+
4
+ module StrongParameters
5
+ # Only allow a list of trusted parameters through.
6
+ def team_params
7
+ strong_params = params.require(:team).permit(
8
+ *permitted_fields,
9
+ :name,
10
+ :time_zone,
11
+ :locale,
12
+ # 🚅 super scaffolding will insert new fields above this line.
13
+ *permitted_arrays,
14
+ # 🚅 super scaffolding will insert new arrays above this line.
15
+ )
16
+
17
+ process_params(strong_params)
18
+
19
+ strong_params
20
+ end
21
+ end
22
+
23
+ included do
24
+ load_and_authorize_resource :team, class: "Team", prepend: true,
25
+ member_actions: (defined?(MEMBER_ACTIONS) ? MEMBER_ACTIONS : []),
26
+ collection_actions: (defined?(COLLECTION_ACTIONS) ? COLLECTION_ACTIONS : [])
27
+
28
+ private
29
+
30
+ include StrongParameters
31
+ end
32
+
33
+ # GET /api/v1/teams
34
+ def index
35
+ end
36
+
37
+ # GET /api/v1/teams/:id
38
+ def show
39
+ end
40
+
41
+ # PATCH/PUT /api/v1/teams/:id
42
+ def update
43
+ if @team.update(team_params)
44
+ render :show
45
+ else
46
+ render json: @team.errors, status: :unprocessable_entity
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,42 @@
1
+ module Api::V1::Users::ControllerBase
2
+ extend ActiveSupport::Concern
3
+
4
+ module StrongParameters
5
+ # Only allow a list of trusted parameters through.
6
+ def user_params
7
+ strong_params = params.require(:user).permit(
8
+ *permitted_fields,
9
+ :email,
10
+ :first_name,
11
+ :last_name,
12
+ :time_zone,
13
+ :locale,
14
+ # 🚅 super scaffolding will insert new fields above this line.
15
+ *permitted_arrays,
16
+ # 🚅 super scaffolding will insert new arrays above this line.
17
+ )
18
+
19
+ process_params(strong_params)
20
+
21
+ strong_params
22
+ end
23
+ end
24
+
25
+ included do
26
+ load_and_authorize_resource :user, class: "User", prepend: true,
27
+ member_actions: (defined?(MEMBER_ACTIONS) ? MEMBER_ACTIONS : []),
28
+ collection_actions: (defined?(COLLECTION_ACTIONS) ? COLLECTION_ACTIONS : [])
29
+
30
+ private
31
+
32
+ include StrongParameters
33
+ end
34
+
35
+ # GET /api/v1/users
36
+ def index
37
+ end
38
+
39
+ # GET /api/v1/users/:id
40
+ def show
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ json.data do
2
+ json.array! @teams, partial: "api/v1/teams/team", as: :team
3
+ end
4
+
5
+ render_pagination(json)
@@ -0,0 +1 @@
1
+ json.partial! "api/v1/teams/team", team: @team
@@ -0,0 +1,5 @@
1
+ json.data do
2
+ json.array! @users, partial: "api/v1/users/user", as: :user
3
+ end
4
+
5
+ render_pagination(json)
@@ -0,0 +1 @@
1
+ json.partial! "api/v1/users/user", user: @user
data/config/routes.rb CHANGED
@@ -1,4 +1,18 @@
1
1
  Rails.application.routes.draw do
2
2
  use_doorkeeper
3
- # mount Api::Base, at: "/api"
3
+
4
+ namespace :api do
5
+ namespace :v1 do
6
+ shallow do
7
+ resources :users
8
+ resources :teams do
9
+ resources :invitations
10
+ resources :memberships
11
+ namespace :platform do
12
+ resources :applications
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
4
18
  end
@@ -1,5 +1,5 @@
1
1
  module BulletTrain
2
2
  module Api
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bullet_train-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Culver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-02 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: standard
@@ -120,6 +120,9 @@ files:
120
120
  - Rakefile
121
121
  - app/assets/config/bullet_train_api_manifest.js
122
122
  - app/controllers/account/platform/applications_controller.rb
123
+ - app/controllers/concerns/api/controllers/base.rb
124
+ - app/controllers/concerns/api/v1/teams/controller_base.rb
125
+ - app/controllers/concerns/api/v1/users/controller_base.rb
123
126
  - app/models/platform/application.rb
124
127
  - app/views/account/platform/applications/_application.json.jbuilder
125
128
  - app/views/account/platform/applications/_breadcrumbs.html.erb
@@ -132,6 +135,10 @@ files:
132
135
  - app/views/account/platform/applications/new.html.erb
133
136
  - app/views/account/platform/applications/show.html.erb
134
137
  - app/views/account/platform/applications/show.json.jbuilder
138
+ - app/views/api/v1/teams/index.json.jbuilder
139
+ - app/views/api/v1/teams/show.json.jbuilder
140
+ - app/views/api/v1/users/index.json.jbuilder
141
+ - app/views/api/v1/users/show.json.jbuilder
135
142
  - config/locales/en/api.en.yml
136
143
  - config/locales/en/me.en.yml
137
144
  - config/locales/en/platform/applications.en.yml