Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ProjectQuery model to the main namespace #15983

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/components/projects/delete_list_modal_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
data: { 'test-selector': MODAL_ID })) do |d| %>
<% d.with_header(variant: :large, mb: 2) %>
<% d.with_body { t(:'projects.lists.delete_modal.text') } %>

<% d.with_footer do %>
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": MODAL_ID })) { I18n.t(:button_cancel) } %>
<%= form_with(url: projects_query_path(query),
<%= form_with(url: project_query_path(query),
method: :delete) do %>
<%= render(Primer::Beta::Button.new(scheme: :danger,
type: :submit)) { I18n.t(:button_delete) } %>
<% end %>
<% end %>
<% end %>
<% end %>
16 changes: 8 additions & 8 deletions app/components/projects/index_page_header_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
header:,
message: t("lists.can_be_saved"),
label: t("button_save"),
href: projects_query_path(query, projects_query_params),
href: project_query_path(query, projects_query_params),
method: :patch
)
elsif can_save_as?
header_save_action(
header:,
message: t("lists.can_be_saved_as"),
label: t("button_save_as"),
href: new_projects_query_path(projects_query_params)
href: new_project_query_path(projects_query_params)
)
end

Expand All @@ -32,7 +32,7 @@
if can_rename?
menu.with_item(
label: t('button_rename'),
href: rename_projects_query_path(query),
href: rename_project_query_path(query),
) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
Expand Down Expand Up @@ -62,7 +62,7 @@
menu_save_item(
menu:,
label: t('button_save'),
href: projects_query_path(query, projects_query_params),
href: project_query_path(query, projects_query_params),
method: :patch
)
end
Expand All @@ -71,7 +71,7 @@
menu_save_item(
menu:,
label: t('button_save_as'),
href: new_projects_query_path(projects_query_params)
href: new_project_query_path(projects_query_params)
)
end

Expand All @@ -96,7 +96,7 @@
menu.with_item(
label: t(:button_unpublish),
scheme: :danger,
href: unpublish_projects_query_path(query),
href: unpublish_project_query_path(query),
content_arguments: { data: { method: :post } }
) do |item|
item.with_leading_visual_icon(icon: 'eye-closed')
Expand All @@ -105,7 +105,7 @@
menu.with_item(
label: t(:button_publish),
scheme: :default,
href: publish_projects_query_path(query),
href: publish_project_query_path(query),
content_arguments: { data: { method: :post } }
) do |item|
item.with_leading_visual_icon(icon: 'eye')
Expand All @@ -132,7 +132,7 @@
render(Primer::OpenProject::PageHeader.new) do |header|
header.with_title(data: { 'test-selector': 'project-query-name'}) do
primer_form_with(model: query,
url: @query.new_record? ? projects_queries_path(projects_query_params) : projects_query_path(@query, projects_query_params),
url: @query.new_record? ? project_queries_path(projects_query_params) : project_query_path(@query, projects_query_params),
scope: 'query',
id: 'project-save-form') do |f|
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BaseContract < ::ModelContract
attribute :orders

def self.model
Queries::Projects::ProjectQuery
ProjectQuery
end

validates :name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def render_project_list(url_for_action: action_name)
end

def project_custom_field_mappings_query
@project_custom_field_mappings_query = Queries::Projects::ProjectQuery.new(
@project_custom_field_mappings_query = ProjectQuery.new(
name: "project-custom-field-mappings-#{@custom_field.id}"
) do |query|
query.where(:available_project_attributes, "=", [@custom_field.id])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects/queries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ def render_result(service_call, success_i18n_key:, error_i18n_key:) # rubocop:di
end

def find_query
@query = Queries::Projects::ProjectQuery.visible(current_user).find(params[:id])
@query = ProjectQuery.visible(current_user).find(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/forms/queries/projects/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Queries::Projects::Form < ApplicationForm
required: true,
autofocus: true,
name: "name",
label: Queries::Projects::ProjectQuery.human_attribute_name(:name),
label: ProjectQuery.human_attribute_name(:name),
placeholder: I18n.t(:"projects.lists.new.placeholder")
)

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/menus/projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ def static_filters(ids)
end

def public_filters
::Queries::Projects::ProjectQuery
::ProjectQuery
.public_lists
.order(:name)
.map { |query| query_menu_item(query) }
end

def my_filters
::Queries::Projects::ProjectQuery
::ProjectQuery
.private_lists(user: current_user)
.order(:name)
.map { |query| query_menu_item(query) }
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def short_project_description(project, length = 255)
end

def projects_columns_options
@projects_columns_options ||= ::Queries::Projects::ProjectQuery
@projects_columns_options ||= ::ProjectQuery
.new
.available_selects
.reject { |c| c.attribute == :hierarchy }
Expand Down
2 changes: 1 addition & 1 deletion app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Member < ApplicationRecord

ALLOWED_ENTITIES = [
"WorkPackage",
"Queries::Projects::ProjectQuery"
"ProjectQuery"
].freeze

extend DeprecatedAlias
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
# ++

module Queries::Projects::ProjectQueries::Scopes
module ProjectQueries::Scopes
module AllowedTo
extend ActiveSupport::Concern

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++

class Queries::Projects::ProjectQuery < ApplicationRecord
class ProjectQuery < ApplicationRecord
include Queries::BaseQuery
include Queries::Serialization::Hash
include HasMembers
Expand Down
6 changes: 3 additions & 3 deletions app/models/queries/projects/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def static_query_status_at_risk
private

def list_with(name)
Queries::Projects::ProjectQuery.new(name: I18n.t(name)) do |query|
ProjectQuery.new(name: I18n.t(name)) do |query|
query.order("lft" => "asc")
query.select(*Setting.enabled_projects_columns, add_not_existing: false)

Expand All @@ -133,7 +133,7 @@ def find_static_query_and_set_attributes(id, params, user, duplicate:)
end

def find_persisted_query_and_set_attributes(id, params, user, duplicate:)
query = Queries::Projects::ProjectQuery.visible(user).find_by(id:)
query = ProjectQuery.visible(user).find_by(id:)

return unless query

Expand All @@ -150,7 +150,7 @@ def find_persisted_query_and_set_attributes(id, params, user, duplicate:)
end

def duplicate_query(query)
Queries::Projects::ProjectQuery.new(query.attributes.slice("filters", "orders", "selects"))
ProjectQuery.new(query.attributes.slice("filters", "orders", "selects"))
end

def set_query_attributes(query, params, user)
Expand Down
58 changes: 29 additions & 29 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
# See COPYRIGHT and LICENSE files for more details.
#++

require 'digest/sha1'
require "digest/sha1"

class User < Principal
VALID_NAME_REGEX = /\A[\d\p{Alpha}\p{Mark}\p{Space}\p{Emoji}'’´\-_.,@()+&*–]+\z/
CURRENT_USER_LOGIN_ALIAS = 'me'.freeze
CURRENT_USER_LOGIN_ALIAS = "me".freeze
USER_FORMATS_STRUCTURE = {
firstname_lastname: %i[firstname lastname],
firstname: [:firstname],
Expand All @@ -45,48 +45,48 @@ class User < Principal
include ::Users::PermissionChecks
extend DeprecatedAlias

has_many :watches, class_name: 'Watcher',
has_many :watches, class_name: "Watcher",
dependent: :delete_all
has_many :changesets, dependent: :nullify
has_many :passwords, -> {
order('id DESC')
}, class_name: 'UserPassword',
order("id DESC")
}, class_name: "UserPassword",
dependent: :destroy,
inverse_of: :user
has_one :rss_token, class_name: '::Token::RSS', dependent: :destroy
has_one :api_token, class_name: '::Token::API', dependent: :destroy
has_one :rss_token, class_name: "::Token::RSS", dependent: :destroy
has_one :api_token, class_name: "::Token::API", dependent: :destroy

# The user might have one invitation token
has_one :invitation_token, class_name: '::Token::Invitation', dependent: :destroy
has_one :invitation_token, class_name: "::Token::Invitation", dependent: :destroy

# everytime a user subscribes to a calendar, a new ical_token is generated
# unlike on other token types, all previously generated ical_tokens are kept
# in order to keep all previously generated ical urls valid and usable
has_many :ical_tokens, class_name: '::Token::ICal', dependent: :destroy
has_many :ical_tokens, class_name: "::Token::ICal", dependent: :destroy

belongs_to :ldap_auth_source, optional: true

# Authorized OAuth grants
has_many :oauth_grants,
class_name: 'Doorkeeper::AccessGrant',
foreign_key: 'resource_owner_id'
class_name: "Doorkeeper::AccessGrant",
foreign_key: "resource_owner_id"

# User-defined oauth applications
has_many :oauth_applications,
class_name: 'Doorkeeper::Application',
class_name: "Doorkeeper::Application",
as: :owner

# Meeting memberships
has_many :meeting_participants,
class_name: 'MeetingParticipant',
class_name: "MeetingParticipant",
inverse_of: :user,
dependent: :destroy

has_many :notification_settings,
dependent: :destroy

has_many :project_queries,
class_name: 'Queries::Projects::ProjectQuery',
class_name: "ProjectQuery",
inverse_of: :user,
dependent: :destroy

Expand All @@ -109,7 +109,7 @@ def self.create_blocked_scope(scope, blocked)
def self.blocked_condition(blocked)
block_duration = Setting.brute_force_block_minutes.to_i.minutes
blocked_if_login_since = Time.now - block_duration
negation = blocked ? '' : 'NOT'
negation = blocked ? "" : "NOT"

["#{negation} (users.failed_login_count >= ? AND users.last_failed_login_on > ?)",
Setting.brute_force_block_after_failed_logins.to_i,
Expand Down Expand Up @@ -141,7 +141,7 @@ def self.blocked_condition(blocked)
validates :password,
confirmation: {
allow_nil: true,
message: ->(*) { I18n.t('activerecord.errors.models.user.attributes.password_confirmation.confirmation') }
message: ->(*) { I18n.t("activerecord.errors.models.user.attributes.password_confirmation.confirmation") }
}

auto_strip_attributes :login, nullify: false
Expand Down Expand Up @@ -210,7 +210,7 @@ def self.try_to_login(login, password, session = nil)

# Tries to authenticate a user in the database via external auth source
# or password stored in the database
def self.try_authentication_for_existing_user(user, password, session = nil)
def self.try_authentication_for_existing_user(user, password, session = nil) # rubocop:disable Metrics/PerceivedComplexity
activate_user! user, session if session

return nil if !user.active? || OpenProject::Configuration.disable_password_login?
Expand Down Expand Up @@ -255,7 +255,7 @@ def self.try_authentication_and_create_user(login, password)

# Returns the user who matches the given autologin +key+ or nil
def self.try_to_autologin(key)
token = Token::AutoLogin.find_by_plaintext_value(key)
token = Token::AutoLogin.find_by_plaintext_value(key) # rubocop:disable Rails/DynamicFindBy
# Make sure there's only 1 token that matches the key
if token && ((token.created_at > Setting.autologin.to_i.day.ago) && token.user && token.user.active?)
token.user
Expand Down Expand Up @@ -295,7 +295,7 @@ def name(formatter = nil)
def authentication_provider
return if identity_url.blank?

identity_url.split(':', 2).first.titleize
identity_url.split(":", 2).first.titleize
end

##
Expand Down Expand Up @@ -525,20 +525,20 @@ def missing_authentication_method?

# Returns the anonymous user. If the anonymous user does not exist, it is created. There can be only
# one anonymous user per database.
def self.anonymous
def self.anonymous # rubocop:disable Metrics/AbcSize
RequestStore[:anonymous_user] ||= begin
anonymous_user = AnonymousUser.first

if anonymous_user.nil?
(anonymous_user = AnonymousUser.new.tap do |u|
u.lastname = 'Anonymous'
u.login = ''
u.firstname = ''
u.mail = ''
u.lastname = "Anonymous"
u.login = ""
u.firstname = ""
u.mail = ""
u.status = User.statuses[:active]
end).save

raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
raise "Unable to create the anonymous user." if anonymous_user.new_record?
end
anonymous_user
end
Expand All @@ -560,7 +560,7 @@ def self.system

system_user.save(validate: false)

raise 'Unable to create the automatic migration user.' unless system_user.persisted?
raise "Unable to create the automatic migration user." unless system_user.persisted?
end

system_user
Expand All @@ -586,7 +586,7 @@ def password_meets_requirements

if former_passwords_include?(password)
errors.add(:password,
I18n.t('activerecord.errors.models.user.attributes.password.reused',
I18n.t("activerecord.errors.models.user.attributes.password.reused",
count: Setting[:password_count_former_banned].to_i))
end
end
Expand All @@ -596,7 +596,7 @@ def password_meets_requirements

def self.mail_regexp(mail)
separators = Regexp.escape(Setting.mail_suffix_separators)
recipient, domain = mail.split('@').map { |part| Regexp.escape(part) }
recipient, domain = mail.split("@").map { |part| Regexp.escape(part) }
skip_suffix_check = recipient.nil? || Setting.mail_suffix_separators.empty? || recipient.match?(/.+[#{separators}].+/)
regexp = "^#{recipient}([#{separators}][^@]+)*@#{domain}$"

Expand Down Expand Up @@ -675,6 +675,6 @@ def log_failed_login_timestamp
end

def self.default_admin_account_changed?
!User.active.find_by_login('admin').try(:current_password).try(:matches_plaintext?, 'admin')
!User.active.find_by_login("admin").try(:current_password).try(:matches_plaintext?, "admin") # rubocop:disable Rails/DynamicFindBy
end
end
4 changes: 3 additions & 1 deletion app/services/params_to_query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def set_query_class(query_class, model)
else
model_name = model.name

"::Queries::#{model_name.pluralize}::#{model_name.demodulize}Query".constantize
# Some queries exist as Queries::Models::ModelQuery others as ModelQuery
"::Queries::#{model_name.pluralize}::#{model_name.demodulize}Query".safe_constantize ||
"::#{model_name.demodulize}Query".constantize
end
end
end
Loading
Loading