Skip to content

Commit 10380fa

Browse files
committed
Add rubocop fixes
1 parent 63b65c2 commit 10380fa

38 files changed

+147
-175
lines changed

app/controllers/api/v2/base_api_controller.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@
22

33
module Api
44
module V2
5-
class BaseApiController < ApplicationController
6-
5+
class BaseApiController < ApplicationController # rubocop:todo Style/Documentation
76
# skipping the standard rails authenticity tokens passed in the UI
87
skip_before_action :verify_authenticity_token
98

109
# call doorkeeper to authorize the request
1110
before_action :doorkeeper_authorize!, except: %i[heartbeat]
12-
1311
# get details of server (e.g. DMPonline) and client app
1412
before_action :get_client_and_server_details
1513

1614
before_action :log_access
1715

1816
# controller can respond to json format requests
19-
respond_to :json
17+
respond_to :json
2018

2119
# set up pages in response
2220
before_action :pagination_params, except: %i[heartbeat]
@@ -38,11 +36,13 @@ def me
3836
# define instance variable json and associated getter and setter methods
3937
attr_accessor :json
4038

41-
def get_client_and_server_details
39+
def get_client_and_server_details # rubocop:todo Naming/AccessorMethodName
4240
@server = ApplicationService.application_name
4341
@client = OauthApplication.find(doorkeeper_token.application_id) if doorkeeper_token
4442
@scopes = doorkeeper_token.scopes.to_a if doorkeeper_token
45-
@resource_owner = User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token && doorkeeper_token.resource_owner_id
43+
return unless doorkeeper_token&.resource_owner_id
44+
45+
@resource_owner = User.find(doorkeeper_token.resource_owner_id)
4646
end
4747

4848
def log_access
@@ -79,8 +79,8 @@ def handle_client_not_authorized
7979
# only allow 100 per page as the max
8080
def pagination_params
8181
max_per_page = Rails.configuration.x.application.api_max_page_size
82-
@page = params.fetch('page', 1).to_i
83-
@per_page = params.fetch('per_page', max_per_page).to_i
82+
@page = params.fetch('page', 1).to_i
83+
@per_page = params.fetch('per_page', max_per_page).to_i
8484
@per_page = max_per_page if @per_page > max_per_page
8585
end
8686

@@ -89,7 +89,6 @@ def paginate_response(results:)
8989
@total_items = results.total_count
9090
results
9191
end
92-
9392
end
9493
end
95-
end
94+
end
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
11
# frozen_string_literal: true
22

3-
module Api
4-
module V2
5-
class PlansController < BaseApiController
6-
respond_to :json
3+
module Api
4+
module V2
5+
class PlansController < BaseApiController # rubocop:todo Style/Documentation
6+
respond_to :json
77

88
# GET /api/v2/plans/:id
99
def show
10-
unless @scopes.include?('read')
11-
raise Pundit::NotAuthorizedError
12-
end
10+
raise Pundit::NotAuthorizedError unless @scopes.include?('read')
1311

1412
@plan = Plan.find_by(id: params[:id])
1513

16-
unless @plan.present?
17-
raise Pundit::NotAuthorizedError
18-
end
14+
raise Pundit::NotAuthorizedError unless @plan.present?
1915

2016
plans_policy = PlansPolicy.new(@resource_owner, @plan)
21-
unless plans_policy.show?
22-
raise Pundit::NotAuthorizedError
23-
end
17+
raise Pundit::NotAuthorizedError unless plans_policy.show?
2418

2519
@items = [@plan]
2620
render '/api/v2/plans/index', status: :ok
2721
end
2822

2923
# GET /api/v2/plans
3024
def index
31-
unless @scopes.include?('read')
32-
raise Pundit::NotAuthorizedError
33-
end
25+
raise Pundit::NotAuthorizedError unless @scopes.include?('read')
3426

3527
@plans = PlansPolicy::Scope.new(@resource_owner).resolve
3628
@items = paginate_response(results: @plans)
3729
render '/api/v2/plans/index', status: :ok
38-
3930
end
4031
end
4132
end
42-
end
33+
end

app/controllers/api/v2/templates_controller.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,16 @@ module Api
44
module V2
55
# provides a list of templates for API V2
66
class TemplatesController < BaseApiController
7-
respond_to :json
7+
respond_to :json
88

99
# GET /api/v2/templates
10-
# rubocop:disable Metrics/AbcSize
1110
def index
12-
unless @scopes.include?('read')
13-
raise Pundit::NotAuthorizedError
14-
end
11+
raise Pundit::NotAuthorizedError unless @scopes.include?('read')
12+
1513
templates = Api::V2::TemplatesPolicy::Scope.new(@resource_owner).resolve
1614
@items = paginate_response(results: templates)
1715
render '/api/v2/templates/index', status: :ok
1816
end
19-
2017
end
2118
end
22-
end
19+
end

app/controllers/application_controller.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,8 @@ def store_location
6666

6767
# rubocop:disable Metrics/AbcSize
6868
def after_sign_in_path_for(_resource)
69-
# ensure oauth2 authorization flow is not interrupted
70-
if user_is_in_oauth_flow
71-
return session[:user_return_to]
72-
end
69+
# ensure oauth2 authorization flow is not interrupted
70+
return session[:user_return_to] if user_is_in_oauth_flow
7371

7472
referer_path = URI(request.referer).path unless request.referer.nil?
7573
if from_external_domain? || referer_path.eql?(new_user_session_path) ||
@@ -82,11 +80,9 @@ def after_sign_in_path_for(_resource)
8280
end
8381
# rubocop:enable Metrics/AbcSize
8482

85-
def after_sign_up_path_for(_resource)
86-
# ensure oauth2 authorization flow is not interrupted
87-
if user_is_in_oauth_flow
88-
return session[:user_return_to]
89-
end
83+
def after_sign_up_path_for(_resource) # rubocop:todo Metrics/AbcSize
84+
# ensure oauth2 authorization flow is not interrupted
85+
return session[:user_return_to] if user_is_in_oauth_flow
9086

9187
referer_path = URI(request.referer).path unless request.referer.nil?
9288
if from_external_domain? ||

app/controllers/concerns/plan_permitted_params.rb

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# frozen_string_literal: true
22

3-
module PlanPermittedParams
3+
module PlanPermittedParams # rubocop:todo Metrics/ModuleLength, Style/Documentation
44
extend ActiveSupport::Concern
55

66
def plan_permitted_params
77
[
88
:created,
9-
:title,
10-
:description,
11-
:language,
9+
:title,
10+
:description,
11+
:language,
1212
:ethical_issues_exist,
1313
:ethical_issues_description,
1414
:ethical_issues_report,
@@ -22,17 +22,17 @@ def plan_permitted_params
2222
end
2323

2424
def identifier_permitted_params
25-
[
26-
:type,
27-
:identifier
25+
%i[
26+
type
27+
identifier
2828
]
2929
end
3030

3131
def contributor_permitted_params
3232
[
33-
:firstname,
34-
:surname,
35-
:mbox,
33+
:firstname,
34+
:surname,
35+
:mbox,
3636
:role,
3737
{ affiliations: affiliation_permitted_params },
3838
{ contributor_ids: identifier_permitted_params }
@@ -41,26 +41,26 @@ def contributor_permitted_params
4141

4242
def affiliation_permitted_params
4343
[
44-
:name,
44+
:name,
4545
:abbreviation,
4646
{ affiliation_ids: identifier_permitted_params }
4747
]
4848
end
4949

5050
def cost_permitted_params
51-
[
52-
:title,
53-
:description,
54-
:value,
55-
:currency_code
51+
%i[
52+
title
53+
description
54+
value
55+
currency_code
5656
]
5757
end
5858

5959
def project_permitted_params
6060
[
61-
:title,
62-
:description,
63-
:start_on,
61+
:title,
62+
:description,
63+
:start_on,
6464
:end_on,
6565
{ funding: funding_permitted_params }
6666
]
@@ -79,14 +79,14 @@ def dataset_permitted_params
7979
[
8080
:title,
8181
:doi_url,
82-
:description,
83-
:type,
84-
:issued,
85-
:language,
86-
:personal_data,
82+
:description,
83+
:type,
84+
:issued,
85+
:language,
86+
:personal_data,
8787
:sensitive_data,
8888
:keywords,
89-
:data_quality_assurance,
89+
:data_quality_assurance,
9090
:preservation_statement,
9191
{ dataset_ids: identifier_permitted_params },
9292
{ metadata: metadatum_permitted_params },
@@ -105,9 +105,9 @@ def metadatum_permitted_params
105105
end
106106

107107
def security_and_privacy_statement_permitted_params
108-
[
109-
:title,
110-
:description
108+
%i[
109+
title
110+
description
111111
]
112112
end
113113

@@ -123,20 +123,20 @@ def distribution_permitted_params
123123
:title,
124124
:description,
125125
:format,
126-
:byte_size,
127-
:access_url,
126+
:byte_size,
127+
:access_url,
128128
:download_url,
129129
:data_access,
130130
:available_until,
131-
{ licenses: license_permitted_params },
131+
{ licenses: license_permitted_params },
132132
{ host: host_permitted_params }
133133
]
134134
end
135135

136136
def license_permitted_params
137-
[
138-
:license_ref,
139-
:start_date
137+
%i[
138+
license_ref
139+
start_date
140140
]
141141
end
142142

@@ -155,5 +155,4 @@ def host_permitted_params
155155
{ host_ids: identifier_permitted_params }
156156
]
157157
end
158-
159-
end
158+
end

app/models/oauth_access_grant.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
#
55
# Table name: oauth_access_grants
66
#
7-
# id: :integer
8-
# resource_owner_id: :integer
7+
# id: :integer
8+
# resource_owner_id: :integer
99
# application_id: :integer
1010
# token: :string
11-
# expires_in: :integer
11+
# expires_in: :integer
1212
# redirect_uri: :text
1313
# scopes: :string
14-
# created_at: :datetime
14+
# created_at: :datetime
1515
# revoked_at: :datetime
1616

1717
class OauthAccessGrant < ApplicationRecord
18-
19-
end
18+
end

app/models/oauth_access_token.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
# revoked_at: :datetime
1616
# previous_refresh_token: :string
1717

18-
1918
class OauthAccessToken < ApplicationRecord
20-
21-
end
19+
end

app/models/oauth_application.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
# Table name: oauth_applications
66
#
77
# id: :integer
8-
# name: :string
9-
# uid: :string
10-
# secret: :string
11-
# redirect_uri: :text
8+
# name: :string
9+
# uid: :string
10+
# secret: :string
11+
# redirect_uri: :text
1212
# scopes: :string
13-
# confidential: :boolean
14-
# created_at: :datetime
13+
# confidential: :boolean
14+
# created_at: :datetime
1515
# updated_at: :datetime
1616

1717
class OauthApplication < ApplicationRecord
18-
19-
end
18+
end

app/models/user.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ class User < ApplicationRecord
9898
has_and_belongs_to_many :notifications, dependent: :destroy,
9999
join_table: 'notification_acknowledgements'
100100

101-
has_many :access_grants, class_name: 'Doorkeeper::AccessGrant', foreign_key: :resource_owner_id, dependent: :delete_all
102-
103-
has_many :access_tokens, class_name: 'Doorkeeper::AccessToken', foreign_key: :resource_owner_id, dependent: :delete_all
104-
101+
has_many :access_grants, class_name: 'Doorkeeper::AccessGrant', foreign_key: :resource_owner_id,
102+
dependent: :delete_all
103+
104+
has_many :access_tokens, class_name: 'Doorkeeper::AccessToken', foreign_key: :resource_owner_id,
105+
dependent: :delete_all
106+
105107
# ===============
106108
# = Validations =
107109
# ===============

0 commit comments

Comments
 (0)