Skip to content

Commit

Permalink
rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Mar 18, 2024
1 parent a50bc24 commit a336b61
Show file tree
Hide file tree
Showing 17 changed files with 363 additions and 362 deletions.
8 changes: 4 additions & 4 deletions app/components/members/role_form_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ See COPYRIGHT and LICENSE files for more details.
<p>
<%= f.submit t(member.new_record? ? :button_add : :button_change), class: "button -primary -small" %>
<%= link_to t(:button_cancel),
'#',
"#",
data: {
action: 'members-form#toggleMembershipEdit',
'members-form-toggling-class-param': row.toggle_item_class_name
action: "members-form#toggleMembershipEdit",
"members-form-toggling-class-param": row.toggle_item_class_name
},
class: 'button -small toggle-membership-button' %>
class: "button -small toggle-membership-button" %>
</p>
<% end %>
6 changes: 3 additions & 3 deletions app/components/members/row_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#++

module Members
class RowComponent < ::RowComponent
class RowComponent < ::RowComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
property :principal
delegate :project, to: :table

Expand Down Expand Up @@ -115,8 +115,8 @@ def administration_settings_link
end

def roles_label
project_roles = member.roles.select { |role| role.is_a?(ProjectRole) }.uniq.sort
label = h project_roles.collect(&:name).join(', ')
project_roles = member.roles.grep(ProjectRole).uniq.sort
label = h project_roles.collect(&:name).join(", ")

if principal&.admin?
label << tag(:br) if project_roles.any?
Expand Down
10 changes: 5 additions & 5 deletions app/components/members/table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#++

module Members
class TableComponent < ::TableComponent
class TableComponent < ::TableComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
options :authorize_update,
:authorize_delete,
:authorize_work_package_shares_view,
Expand Down Expand Up @@ -59,8 +59,8 @@ def subselected_member_ids(model)
Member
.where(
id: model
.reselect('DISTINCT ON (members.user_id) members.id')
.reorder('members.user_id, members.entity_type NULLS FIRST')
.reselect("DISTINCT ON (members.user_id) members.id")
.reorder("members.user_id, members.entity_type NULLS FIRST")
)
end

Expand Down Expand Up @@ -92,7 +92,7 @@ def header_options(name)
caption =
case name
when :shared
I18n.t('members.columns.shared')
I18n.t("members.columns.shared")
else
User.human_attribute_name(name)
end
Expand All @@ -115,7 +115,7 @@ def empty_row_message
if is_filtered
I18n.t :notice_no_principals_found
else
I18n.t :'members.index.no_results_title_text'
I18n.t :"members.index.no_results_title_text"
end
end
end
Expand Down
30 changes: 16 additions & 14 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def create
end

if overall_result.empty?
flash[:error] = I18n.t('activerecord.errors.models.member.principal_blank')
redirect_to project_members_path(project_id: @project, status: 'all')
flash[:error] = I18n.t("activerecord.errors.models.member.principal_blank")
redirect_to project_members_path(project_id: @project, status: "all")
elsif overall_result.all?(&:success?)
display_success(members_added_notice(overall_result.map(&:result)))
flash[:notice] = members_added_notice(overall_result.map(&:result))

redirect_to project_members_path(project_id: @project, status: 'all')
redirect_to project_members_path(project_id: @project, status: "all")
else
display_error(overall_result.first)
display_error(overall_result.first, now: true)

set_index_data!

respond_to do |format|
format.html { render 'index' }
format.html { render "index" }
end
end
end
Expand All @@ -72,7 +72,7 @@ def update
.call(permitted_params.member)

if service_call.success?
display_success(I18n.t(:notice_successful_update))
flash[:notice] = I18n.t(:notice_successful_update)
else
display_error(service_call)
end
Expand Down Expand Up @@ -129,7 +129,7 @@ def build_members
end

if @email
principals << { id: @email, name: I18n.t('members.invite_by_mail', mail: @email) }
principals << { id: @email, name: I18n.t("members.invite_by_mail", mail: @email) }
end

principals
Expand Down Expand Up @@ -188,7 +188,7 @@ def set_index_data!
def set_roles_and_principles!
@roles = ProjectRole.givable
# Check if there is at least one principal that can be added to the project
@principals_available = possible_members('', 1)
@principals_available = possible_members("", 1)
end

def possible_members(criteria, limit)
Expand Down Expand Up @@ -223,11 +223,13 @@ def sort_by_groups_last(members)
members.sort_by { |m| group_ids.include?(m.user_id) ? 1 : -1 }
end

def display_error(service_call)
flash[:error] = service_call.errors.full_messages.compact.join(', ')
end
def display_error(service_call, now: false)
message = service_call.errors.full_messages.compact.join(", ")

def display_success(message)
flash[:notice] = message
if now
flash.now[:error] = message
else
flash[:error] = message
end
end
end
52 changes: 26 additions & 26 deletions app/helpers/work_packages_filter_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module WorkPackagesFilterHelper
def project_work_packages_closed_version_path(version, options = {})
query = {
f: [
filter_object('status_id', 'c'),
filter_object('version_id', '=', version.id)
filter_object("status_id", "c"),
filter_object("version_id", "=", version.id)
]
}
project_work_packages_with_query_path(version.project, query, options)
Expand All @@ -41,8 +41,8 @@ def project_work_packages_closed_version_path(version, options = {})
def project_work_packages_open_version_path(version, options = {})
query = {
f: [
filter_object('status_id', 'o'),
filter_object('version_id', '=', version.id)
filter_object("status_id", "o"),
filter_object("version_id", "=", version.id)
]
}
project_work_packages_with_query_path(version.project, query, options)
Expand All @@ -51,8 +51,8 @@ def project_work_packages_open_version_path(version, options = {})
def project_work_packages_shared_with_path(principal, project, options = {})
query = {
f: [
filter_object('status_id', '*'),
filter_object('shared_with_user', '=', principal.id)
filter_object("status_id", "*"),
filter_object("shared_with_user", "=", principal.id)
]
}
project_work_packages_with_query_path(project, query, options)
Expand All @@ -61,8 +61,8 @@ def project_work_packages_shared_with_path(principal, project, options = {})
def project_work_packages_shared_with_me_path(project, options = {})
query = {
f: [
filter_object('status_id', '*'),
filter_object('shared_with_me', '=', 't')
filter_object("status_id", "*"),
filter_object("shared_with_me", "=", "t")
]
}
project_work_packages_with_query_path(project, query, options)
Expand All @@ -71,8 +71,8 @@ def project_work_packages_shared_with_me_path(project, options = {})
def project_work_packages_with_ids_path(ids, project, options = {})
query = {
f: [
filter_object('status_id', '*'),
filter_object('id', '=', ids)
filter_object("status_id", "*"),
filter_object("id", "=", ids)
]
}
project_work_packages_with_query_path(project, query, options)
Expand All @@ -83,9 +83,9 @@ def project_work_packages_with_ids_path(ids, project, options = {})
def project_report_property_path(project, property_name, property_id, options = {})
query = {
f: [
filter_object('status_id', '*'),
filter_object('subproject_id', '!*'),
filter_object(property_name, '=', property_id)
filter_object("status_id", "*"),
filter_object("subproject_id", "!*"),
filter_object(property_name, "=", property_id)
],
t: default_sort
}
Expand All @@ -95,9 +95,9 @@ def project_report_property_path(project, property_name, property_id, options =
def project_report_property_status_path(project, status_id, property, property_id, options = {})
query = {
f: [
filter_object('status_id', '=', status_id),
filter_object('subproject_id', '!*'),
filter_object(property, '=', property_id)
filter_object("status_id", "=", status_id),
filter_object("subproject_id", "!*"),
filter_object(property, "=", property_id)
],
t: default_sort
}
Expand All @@ -107,9 +107,9 @@ def project_report_property_status_path(project, status_id, property, property_i
def project_report_property_open_path(project, property, property_id, options = {})
query = {
f: [
filter_object('status_id', 'o'),
filter_object('subproject_id', '!*'),
filter_object(property, '=', property_id)
filter_object("status_id", "o"),
filter_object("subproject_id", "!*"),
filter_object(property, "=", property_id)
],
t: default_sort
}
Expand All @@ -119,9 +119,9 @@ def project_report_property_open_path(project, property, property_id, options =
def project_report_property_closed_path(project, property, property_id, options = {})
query = {
f: [
filter_object('status_id', 'c'),
filter_object('subproject_id', '!*'),
filter_object(property, '=', property_id)
filter_object("status_id", "c"),
filter_object("subproject_id", "!*"),
filter_object(property, "=", property_id)
],
t: default_sort
}
Expand All @@ -131,9 +131,9 @@ def project_report_property_closed_path(project, property, property_id, options
def project_version_property_path(version, property_name, property_id, options = {})
query = {
f: [
filter_object('status_id', '*'),
filter_object('version_id', '=', version.id),
filter_object(property_name, '=', property_id)
filter_object("status_id", "*"),
filter_object("version_id", "=", version.id),
filter_object(property_name, "=", property_id)
],
t: default_sort
}
Expand All @@ -143,7 +143,7 @@ def project_version_property_path(version, property_name, property_id, options =
private

def default_sort
'updated_at:desc'
"updated_at:desc"
end

def project_work_packages_with_query_path(project, query, options = {})
Expand Down
2 changes: 1 addition & 1 deletion app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Member < ApplicationRecord
].freeze

extend DeprecatedAlias
belongs_to :principal, foreign_key: 'user_id', inverse_of: 'members', optional: false
belongs_to :principal, foreign_key: "user_id", inverse_of: "members", optional: false
belongs_to :entity, polymorphic: true, optional: true
belongs_to :project, optional: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def with_shared_work_packages_info(only_role_id: nil)
Member
.from("#{Member.quoted_table_name} members")
.joins(shared_work_packages_sql(only_role_id))
.select('members.*')
.select("members.*")
.select("COALESCE(members_sums.shared_work_package_ids, '{}') AS shared_work_package_ids")
.select("COALESCE(members_sums.other_shared_work_packages_count, 0) AS other_shared_work_packages_count")
.select("COALESCE(members_sums.direct_shared_work_packages_count, 0) AS direct_shared_work_packages_count")
Expand Down
26 changes: 13 additions & 13 deletions spec/contracts/members/delete_contract_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@
# See COPYRIGHT and LICENSE files for more details.
#++

require 'spec_helper'
require 'contracts/shared/model_contract_shared_context'
require "spec_helper"
require "contracts/shared/model_contract_shared_context"

RSpec.describe Members::DeleteContract do
include_context 'ModelContract shared context'
include_context "ModelContract shared context"

let(:contract) { described_class.new(member, current_user) }
let(:member) { build_stubbed(:member, project:, roles:, principal:) }
let(:project) { build_stubbed(:project) }
let(:roles) { [build_stubbed(:project_role)] }
let(:principal) { build_stubbed(:user) }

context 'member is deletable' do
it_behaves_like 'contract is valid for active admins and invalid for regular users'
context "when member is deletable" do
it_behaves_like "contract is valid for active admins and invalid for regular users"

include_examples 'contract reuses the model errors' do
include_examples "contract reuses the model errors" do
let(:current_user) { build_stubbed(:user) }
end

context 'user has permission' do
context "when user has permission" do
let(:current_user) { build_stubbed(:user) }

before do
Expand All @@ -54,22 +54,22 @@
end
end

it_behaves_like 'contract is valid'
it_behaves_like "contract is valid"
end
end

context 'when member is not deletable' do
context "when member is not deletable" do
before do
allow(member).to receive(:some_roles_deletable?).and_return(false)
end

context 'for admin' do
context "for admin" do
let(:current_user) { build_stubbed(:admin) }

it_behaves_like 'contract is invalid'
it_behaves_like "contract is invalid"
end

context 'when user has permission' do
context "when user has permission" do
let(:current_user) { build_stubbed(:user) }

before do
Expand All @@ -78,7 +78,7 @@
end
end

it_behaves_like 'contract is invalid'
it_behaves_like "contract is invalid"
end
end
end
Loading

0 comments on commit a336b61

Please sign in to comment.