Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

fixed rubocop and eslint

Jonas Jabaria605e054ca3d
diff --git a/app/contracts/queries/ical_sharing_contract.rb b/app/contracts/queries/ical_sharing_contract.rb
index 35d76b01a41..dc2cf5198d3 100644
--- a/app/contracts/queries/ical_sharing_contract.rb
+++ b/app/contracts/queries/ical_sharing_contract.rb
@@ -43,16 +43,14 @@ module Queries
end
def query_visible_for_user?
- begin
- User.execute_as(user) do
- Query
- .visible(user)
- .find(model.id)
- .present?
- end
- rescue
- false
+ User.execute_as(user) do
+ Query
+ .visible(user)
+ .find(model.id)
+ .present?
end
+ rescue StandardError
+ false
end
def token_valid_for_query?
diff --git a/app/models/query.rb b/app/models/query.rb
index 11c00d0393d..0f580514738 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -37,17 +37,18 @@ class Query < ApplicationRecord
belongs_to :user
has_many :views,
dependent: :destroy
- has_many :ical_token_query_assignments
- has_many :ical_tokens,
+ has_many :ical_token_query_assignments
+ has_many :ical_tokens,
through: :ical_token_query_assignments,
class_name: 'Token::ICal'
+ # no `dependent: :destroy` as the ical_tokens are destroyed in the following before_destroy callback
+ # dependent: :destroy is not possible as this would only delete the ical_token_query_assignments
+ before_destroy :destroy_ical_tokens
serialize :filters, Queries::WorkPackages::FilterSerializer
serialize :column_names, Array
serialize :sort_criteria, Array
- before_destroy :destroy_ical_tokens
-
validates :name,
presence: true,
length: { maximum: 255 }
@@ -476,9 +477,8 @@ class Query < ApplicationRecord
end
# dependent::destroy does not work for has_many :through associations
+ # only the ical_token_query_assignments would be destroyed
def destroy_ical_tokens
- ical_tokens.each do |token|
- token.destroy
- end
+ ical_tokens.each(&:destroy)
end
end
diff --git a/frontend/src/app/features/calendar/openproject-calendar.module.ts b/frontend/src/app/features/calendar/openproject-calendar.module.ts
index d358fa50bd9..cf30b569405 100644
--- a/frontend/src/app/features/calendar/openproject-calendar.module.ts
+++ b/frontend/src/app/features/calendar/openproject-calendar.module.ts
@@ -62,7 +62,7 @@ import { QueryGetIcalUrlModalComponent } from 'core-app/shared/components/modals
FullCalendarModule,
// Angular reactive forms, required for QueryGetIcalUrlModalComponent
- ReactiveFormsModule
+ ReactiveFormsModule,
],
declarations: [
// Work package calendars
@@ -70,7 +70,7 @@ import { QueryGetIcalUrlModalComponent } from 'core-app/shared/components/modals
WorkPackagesCalendarComponent,
TimeEntryCalendarComponent,
CalendarSidemenuComponent,
- QueryGetIcalUrlModalComponent
+ QueryGetIcalUrlModalComponent,
],
exports: [
WorkPackagesCalendarComponent,
diff --git a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts
index 45d662da8e9..a344645008d 100644
--- a/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts
+++ b/frontend/src/app/shared/components/modals/get-ical-url-modal/query-get-ical-url.modal.ts
@@ -104,7 +104,9 @@ export class QueryGetIcalUrlModalComponent extends OpModalComponent implements O
ngOnInit():void {
super.ngOnInit();
- if (!this.querySpace.query.value) {
+ if (this.querySpace.query.value) {
+ this.query = this.querySpace.query.value!;
+ } else {
this.toastService.addError(
this.I18n.t('js.ical_sharing_modal.inital_setup_error_message'),
);
@@ -112,8 +114,6 @@ export class QueryGetIcalUrlModalComponent extends OpModalComponent implements O
setTimeout(() => {
this.closeMe();
}, 10);
- } else {
- this.query = this.querySpace.query.value!;
}
}
@@ -121,7 +121,7 @@ export class QueryGetIcalUrlModalComponent extends OpModalComponent implements O
if (!navigator.clipboard) {
// fallback for browsers that don't support clipboard API at all
this.toastService.addWarning(
- this.I18n.t('js.ical_sharing_modal.copy_url_error_text', { icalUrl: url })
+ this.I18n.t('js.ical_sharing_modal.copy_url_error_text', { icalUrl: url }),
);
} else {
void navigator.clipboard.writeText(url)
@@ -131,7 +131,7 @@ export class QueryGetIcalUrlModalComponent extends OpModalComponent implements O
.catch(() => {
// fallback when running into e.g. browser permission errors
this.toastService.addWarning(
- this.I18n.t('js.ical_sharing_modal.copy_url_error_text', { icalUrl: url })
+ this.I18n.t('js.ical_sharing_modal.copy_url_error_text', { icalUrl: url }),
);
});
}
diff --git a/modules/calendar/app/models/ical_token_query_assignment.rb b/modules/calendar/app/models/ical_token_query_assignment.rb
index 98351546960..3c13c32866f 100644
--- a/modules/calendar/app/models/ical_token_query_assignment.rb
+++ b/modules/calendar/app/models/ical_token_query_assignment.rb
@@ -29,8 +29,10 @@
class ICalTokenQueryAssignment < ApplicationRecord
self.table_name = 'ical_token_query_assignments'
- belongs_to :ical_token, class_name: 'Token::ICal', required: true
- belongs_to :query, required: true
+ # rubocop:disable Rails/BelongsTo
+ belongs_to :ical_token, class_name: 'Token::ICal', optional: true
+ belongs_to :query, optional: true
+ # rubocop:enable Rails/BelongsTo
validates :name, presence: true
validate :unique_name_per_user_and_query
@@ -39,7 +41,7 @@ class ICalTokenQueryAssignment < ApplicationRecord
if ical_token.nil? || ical_token.user_id.nil?
raise "Cannot validate uniqueness of name for #{self.class} without ical_token.user_id"
end
-
+
name_already_taken_for_query_and_user = self.class.joins(:ical_token)
.exists?(name:, query_id:, ical_token: { user_id: ical_token.user_id })
diff --git a/modules/calendar/app/services/calendar/create_ical_service.rb b/modules/calendar/app/services/calendar/create_ical_service.rb
index a0ca2a371ab..5d542ed1690 100644
--- a/modules/calendar/app/services/calendar/create_ical_service.rb
+++ b/modules/calendar/app/services/calendar/create_ical_service.rb
@@ -58,19 +58,23 @@ module Calendar
end
def add_values_to_event(event, work_package)
- event.uid = event_uid_value(work_package)
- event.organizer = organizer_value(work_package)
- event.summary = summary_value(work_package)
- event.dtstamp = dtstamp_value(work_package)
- event.dtstart = dtstart_value(work_package)
- event.dtend = dtend_value(work_package)
- event.location = location_value(work_package)
- event.description = description_value(work_package)
+ %i[
+ uid
+ organizer
+ summary
+ dtstamp
+ dtstart
+ dtend
+ location
+ description
+ ].each do |value|
+ event.send("#{value}=", send("#{value}_value", work_package))
+ end
add_attendee_value(event, work_package)
end
- def event_uid_value(work_package)
+ def uid_value(work_package)
"#{work_package.id}@#{host}"
end
@@ -85,7 +89,7 @@ module Calendar
Icalendar::Values::CalAddress.new(
"mailto:#{work_package.author&.mail}",
cn: work_package.author&.name
- )
+ )
end
def summary_value(work_package)
diff --git a/modules/calendar/app/services/calendar/ical_response_service.rb b/modules/calendar/app/services/calendar/ical_response_service.rb
index cefdaa6ca00..e28fd7bce67 100644
--- a/modules/calendar/app/services/calendar/ical_response_service.rb
+++ b/modules/calendar/app/services/calendar/ical_response_service.rb
@@ -47,7 +47,7 @@ module Calendar
ical_string = ical_generation(query, user)
end
- ServiceResult.new(success:, result: ical_string, errors:)
+ ServiceResult.new(success:, result: ical_string, errors:)
end
protected
diff --git a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb b/modules/calendar/spec/services/resolve_work_packages_service_spec.rb
index e8d78c7d87a..b6a2adeea18 100644
--- a/modules/calendar/spec/services/resolve_work_packages_service_spec.rb
+++ b/modules/calendar/spec/services/resolve_work_packages_service_spec.rb
@@ -84,7 +84,7 @@ describe Calendar::ResolveWorkPackagesService, type: :model do
context 'for a valid query' do
before do
# Add typical calendar filters which are present for calendar queries
- query.add_filter(:dates_interval, "<>d", [Time.zone.today, Time.zone.today+30.days])
+ query.add_filter(:dates_interval, "<>d", [Time.zone.today, Time.zone.today + 30.days])
# login for this isolated test:
# in context of the whole iCalendar API flow, the user is not logged in but resolved from the token
diff --git a/spec/contracts/queries/ical_sharing_contract_spec.rb b/spec/contracts/queries/ical_sharing_contract_spec.rb
index 388b682516a..2c522a81b41 100644
--- a/spec/contracts/queries/ical_sharing_contract_spec.rb
+++ b/spec/contracts/queries/ical_sharing_contract_spec.rb
@@ -40,13 +40,13 @@ describe Queries::ICalSharingContract do
end
let(:current_user) do
create(:user,
- member_in_project: project,
- member_with_permissions: permissions)
+ member_in_project: project,
+ member_with_permissions: permissions)
end
let(:ical_token) { create(:ical_token, user: current_user, query:, name: "Some Token") }
- # override as this contract additionally needs the ical_token
- let(:contract) { described_class.new(query, current_user, options: { ical_token: ical_token }) }
+ # override as this contract additionally needs the ical_token
+ let(:contract) { described_class.new(query, current_user, options: { ical_token: }) }
describe 'private query' do
let(:public) { false }
@@ -105,7 +105,7 @@ describe Queries::ICalSharingContract do
context 'when author is someone else' do
let(:user) { create(:user) } # other user as owner of query
-
+
it_behaves_like 'contract user is unauthorized' # authorized as query is public
end
end
@@ -117,7 +117,7 @@ describe Queries::ICalSharingContract do
context 'when author is someone else' do
let(:user) { create(:user) } # other user as owner of query
-
+
it_behaves_like 'contract is valid' # authorized as query is public
end
end
@@ -128,8 +128,8 @@ describe Queries::ICalSharingContract do
let(:other_project) { create(:project) }
let(:current_user) do
create(:user,
- member_in_project: other_project,
- member_with_permissions: permissions)
+ member_in_project: other_project,
+ member_with_permissions: permissions)
end
context 'when user is author but not member of project (anymore)' do
diff --git a/spec/factories/ical_token_query_assignment_factory.rb b/spec/factories/ical_token_query_assignment_factory.rb
index 8367ca5e100..652ecaa26d7 100644
--- a/spec/factories/ical_token_query_assignment_factory.rb
+++ b/spec/factories/ical_token_query_assignment_factory.rb
@@ -28,7 +28,7 @@
FactoryBot.define do
factory :ical_token_query_assignment do
- association :ical_token
- association :query
+ ical_token
+ query
end
end
diff --git a/spec/factories/token_factory.rb b/spec/factories/token_factory.rb
index bf56e2748b9..f205b400910 100644
--- a/spec/factories/token_factory.rb
+++ b/spec/factories/token_factory.rb
@@ -64,7 +64,7 @@ FactoryBot.define do
end
factory :ical_token, class: '::Token::ICal' do
- association :user
+ user
transient do
query { nil }
@@ -72,11 +72,10 @@ FactoryBot.define do
end
after(:build) do |token, evaluator|
- token.ical_token_query_assignment = build(:ical_token_query_assignment,
- query: evaluator.query,
- name: evaluator.name,
- ical_token: token
- )
+ token.ical_token_query_assignment = build(:ical_token_query_assignment,
+ query: evaluator.query,
+ name: evaluator.name,
+ ical_token: token)
end
end
end
diff --git a/spec/models/token/ical_token_spec.rb b/spec/models/token/ical_token_spec.rb
index 2f9ff81fa74..e493a038f5b 100644
--- a/spec/models/token/ical_token_spec.rb
+++ b/spec/models/token/ical_token_spec.rb
@@ -192,13 +192,13 @@ describe Token::ICal do
describe 'dependent destroyed' do
context 'when associated query is destroyed' do
it 'the ical_token is destroyed as well' do
- ical_token = described_class.create(
+ described_class.create(
user:,
ical_token_query_assignment_attributes: { query:, name: }
)
expect do
query.destroy!
- end.to change { described_class.count }.by(-1)
+ end.to change(described_class, :count).by(-1)
expect(described_class.all).to be_empty
expect(ICalTokenQueryAssignment.all).to be_empty
@@ -207,13 +207,13 @@ describe Token::ICal do
context 'when associated user is destroyed' do
it 'the ical_token is destroyed as well' do
- ical_token = described_class.create(
+ described_class.create(
user:,
ical_token_query_assignment_attributes: { query:, name: }
)
expect do
user.destroy!
- end.to change { described_class.count }.by(-1)
+ end.to change(described_class, :count).by(-1)
expect(described_class.all).to be_empty
expect(ICalTokenQueryAssignment.all).to be_empty
@@ -228,7 +228,7 @@ describe Token::ICal do
)
expect do
ical_token.destroy!
- end.to change { ICalTokenQueryAssignment.count }.by(-1)
+ end.to change(ICalTokenQueryAssignment, :count).by(-1)
expect(ICalTokenQueryAssignment.all).to be_empty
end