Skip to content

Commit

Permalink
[#53620] fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharonus committed Sep 6, 2024
1 parent 735bc8e commit f65f697
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 28 deletions.
12 changes: 5 additions & 7 deletions app/contracts/oauth/applications/base_contract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ def self.model
private

def validate_admin_only
unless user.active_admin?
errors.add :base, :error_unauthorized
end
errors.add :base, :error_unauthorized unless user.admin?
end

def validate_integration
if (model.integration_id.nil? && model.integration_type.present?) ||
(model.integration_id.present? && model.integration_type.nil?)
errors.add :integration, :invalid
end
both = model.integration_id.present? && model.integration_type.present?
none = model.integration_id.nil? && model.integration_type.nil?

errors.add :integration, :invalid unless both || none
end

def validate_client_credential_user
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/oauth/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ def edit; end
def create
call = ::OAuth::Applications::CreateService.new(user: current_user)
.call(permitted_params.oauth_application)
result = call.result

if call.success?
flash[:notice] = t(:notice_successful_create)
flash[:_application_secret] = call.result.plaintext_secret
redirect_to action: :show, id: call.result.id
flash[:_application_secret] = result.plaintext_secret
redirect_to action: :show, id: result.id
else
@application = call.result
@application = result
render action: :new
end
end
Expand Down
4 changes: 0 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,6 @@ def wants_comments_in_reverse_order?
pref.comments_in_reverse_order?
end

def active_admin?
admin? && active?
end

def self.find_by_rss_key(key)
return nil unless Setting.feeds_enabled?

Expand Down
10 changes: 7 additions & 3 deletions app/seeders/oauth_applications_seeder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 the OpenProject GmbH
Expand Down Expand Up @@ -26,6 +28,8 @@
# See COPYRIGHT and LICENSE files for more details.
#++
class OAuthApplicationsSeeder < Seeder
OPENPROJECT_MOBILE_APP_UID = "DgJZ7Rat23xHZbcq_nxPg5RUuxljonLCN7V7N7GoBAA"

def seed_data!
call = create_app
unless call.success?
Expand All @@ -37,11 +41,11 @@ def seed_data!
end

def applicable?
Doorkeeper::Application.where(builtin: true).empty?
Doorkeeper::Application.find_by(id: OPENPROJECT_MOBILE_APP_UID).nil?
end

def not_applicable_message
"No need to seed oauth appplications as they are already present."
"No need to seed oauth applications as they are already present."
end

def create_app
Expand All @@ -53,7 +57,7 @@ def create_app
redirect_uri: "openprojectapp://oauth-callback",
builtin: true,
confidential: false,
uid: "DgJZ7Rat23xHZbcq_nxPg5RUuxljonLCN7V7N7GoBAA"
uid: OPENPROJECT_MOBILE_APP_UID
)
end
end
6 changes: 4 additions & 2 deletions db/migrate/20240513135928_extend_oauth_applications.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class ExtendOAuthApplications < ActiveRecord::Migration[7.1]
def change
add_column :oauth_applications, :builtin, :boolean, default: false
add_column :oauth_applications, :enabled, :boolean, default: true
change_table :oauth_applications, bulk: true do |t|
t.column :enabled, :boolean, default: true, null: false
t.column :builtin, :boolean, default: false, null: false
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

context "with a seeded application" do
before do
::OAuthApplicationsSeeder.new.seed_data!
OAuthApplicationsSeeder.new.seed_data!
end

it "does not allow editing or deleting the seeded application" do
Expand All @@ -105,14 +105,14 @@
expect(page).to have_css("td.builtin .icon-checkmark")
expect(page).to have_css("td.enabled .icon-checkmark")

expect(page).not_to have_css("td.buttons", text: "Edit")
expect(page).not_to have_css("td.buttons", text: "Delete")
expect(page).to have_no_css("td.buttons", text: "Edit")
expect(page).to have_no_css("td.buttons", text: "Delete")

expect(page).to have_css("td.buttons", text: "Deactivate")
click_link_or_button "Deactivate"

expect(page).to have_css("td.builtin .icon-checkmark")
expect(page).not_to have_css("td.enabled .icon-checkmark")
expect(page).to have_no_css("td.enabled .icon-checkmark")

app = Doorkeeper::Application.last
expect(app).to be_builtin
Expand Down
4 changes: 2 additions & 2 deletions spec/services/oauth/applications/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
require "spec_helper"
require "services/base_services/behaves_like_create_service"

RSpec.describe OAuth::Applications::CreateService, type: :model do
RSpec.describe OAuth::Applications::CreateService, type: :model do # rubocop:disable RSpec/SpecFilePathFormat
it_behaves_like "BaseServices create service" do
let(:factory) { :oauth_application }
let(:model_class) { Doorkeeper::Application }
let(:factory) { :oauth_application }
end
end
2 changes: 1 addition & 1 deletion spec/services/oauth/applications/delete_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
require "spec_helper"
require "services/base_services/behaves_like_delete_service"

RSpec.describe OAuth::Applications::DeleteService, type: :model do
RSpec.describe OAuth::Applications::DeleteService, type: :model do # rubocop:disable RSpec/SpecFilePathFormat
it_behaves_like "BaseServices delete service" do
let(:factory) { :oauth_application }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

require "spec_helper"

RSpec.describe OAuth::Applications::SetAttributesService, type: :model do
RSpec.describe OAuth::Applications::SetAttributesService, type: :model do # rubocop:disable RSpec/SpecFilePathFormat
let(:current_user) { build_stubbed(:admin) }

let(:contract_instance) do
Expand Down
2 changes: 1 addition & 1 deletion spec/services/oauth/applications/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
require "spec_helper"
require "services/base_services/behaves_like_update_service"

RSpec.describe OAuth::Applications::UpdateService, type: :model do
RSpec.describe OAuth::Applications::UpdateService, type: :model do # rubocop:disable RSpec/SpecFilePathFormat
it_behaves_like "BaseServices update service" do
let(:factory) { :oauth_application }
end
Expand Down

0 comments on commit f65f697

Please sign in to comment.