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

Placeholder user project members (#8961)

ulferts5ea185ef66a4
diff --git a/app/cells/members/row_cell.rb b/app/cells/members/row_cell.rb
index d1bc629ade0..0753ebcf9ad 100644
--- a/app/cells/members/row_cell.rb
+++ b/app/cells/members/row_cell.rb
@@ -1,5 +1,7 @@
module Members
class RowCell < ::RowCell
+ include UsersHelper
+
property :principal
def member
@@ -74,7 +76,7 @@ module Members
end
def status
- I18n.t("status_#{model.principal.status_name}")
+ translate_user_status(model.principal.status)
end
def may_update?
diff --git a/app/cells/users/row_cell.rb b/app/cells/users/row_cell.rb
index ad24d477540..361de57e769 100644
--- a/app/cells/users/row_cell.rb
+++ b/app/cells/users/row_cell.rb
@@ -8,7 +8,7 @@ module Users
end
def row_css_class
- status = %w(anon active registered locked)[user.status]
+ status = user.status
blocked = "blocked" if user.failed_too_many_recent_login_attempts?
["user", status, blocked].compact.join(" ")
diff --git a/app/contracts/members/create_contract.rb b/app/contracts/members/create_contract.rb
index 06396bf0ec1..b1c960e758f 100644
--- a/app/contracts/members/create_contract.rb
+++ b/app/contracts/members/create_contract.rb
@@ -28,19 +28,24 @@
module Members
class CreateContract < BaseContract
+ include AssignableValuesContract
+
attribute :project
attribute :user_id
attribute :principal do
principal_assignable
end
+ def assignable_principals
+ Principal.possible_member(project)
+ end
+
private
def principal_assignable
return if principal.nil?
- # Only users have the `locked?` shorthand
- if principal.builtin? || principal.status == Principal::STATUSES[:locked]
+ if principal.builtin? || principal.locked?
errors.add(:principal, :unassignable)
end
end
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index 8a306982d2d..2ce7710ab68 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -70,7 +70,7 @@ module WorkPackages
validate_people_visible :assigned_to,
'assigned_to_id',
- model.project.possible_assignee_members
+ assignable_assignees
end
attribute :responsible_id do
@@ -78,7 +78,7 @@ module WorkPackages
validate_people_visible :responsible,
'responsible_id',
- model.project.possible_responsible_members
+ assignable_responsibles
end
attribute :schedule_manually
@@ -178,6 +178,15 @@ module WorkPackages
model.project&.budgets
end
+ def assignable_assignees
+ if model.project
+ Principal.possible_assignee(model.project)
+ else
+ Principal.none
+ end
+ end
+ alias_method :assignable_responsibles, :assignable_assignees
+
private
attr_reader :can
@@ -298,7 +307,7 @@ module WorkPackages
end
def principal_visible?(id, list)
- list.exists?(user_id: id)
+ list.exists?(id: id)
end
def start_before_soonest_start?
diff --git a/app/controllers/concerns/user_invitation.rb b/app/controllers/concerns/user_invitation.rb
index 7825f617de7..a2bcdafe7ff 100644
--- a/app/controllers/concerns/user_invitation.rb
+++ b/app/controllers/concerns/user_invitation.rb
@@ -59,7 +59,7 @@ module UserInvitation
login: login,
firstname: first_name,
lastname: last_name,
- status: Principal::STATUSES[:invited]
+ status: Principal.statuses[:invited]
assign_user_attributes(user)
diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb
index b5df1f8a1e3..73f3f1e80a0 100644
--- a/app/controllers/members_controller.rb
+++ b/app/controllers/members_controller.rb
@@ -102,9 +102,7 @@ class MembersController < ApplicationController
end
def autocomplete_for_member
- @principals = Principal
- .possible_members(params[:q], 100)
- .where.not(id: @project.principals)
+ @principals = possible_members(params[:q], 100)
@email = suggest_invite_via_email? current_user,
params[:q],
@@ -165,7 +163,14 @@ class MembersController < ApplicationController
def set_roles_and_principles!
@roles = Role.givable
# Check if there is at least one principal that can be added to the project
- @principals_available = @project.possible_members('', 1)
+ @principals_available = possible_members('', 1)
+ end
+
+ def possible_members(criteria, limit)
+ Principal
+ .possible_member(@project)
+ .like(criteria)
+ .limit(limit)
end
def index_members
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c3afd48e5cc..290c3dcf950 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -208,8 +208,7 @@ class UsersController < ApplicationController
@user.activate
end
# Was the account activated? (do it before User#save clears the change)
- was_activated = (@user.status_change == [User::STATUSES[:registered],
- User::STATUSES[:active]])
+ was_activated = (@user.status_change == %w[registered active])
if params[:activate] && @user.missing_authentication_method?
flash[:error] = I18n.t(:error_status_change_failed,
@@ -229,7 +228,7 @@ class UsersController < ApplicationController
end
def resend_invitation
- status = Principal::STATUSES[:invited]
+ status = Principal.statuses[:invited]
@user.update status: status if @user.status != status
token = UserInvitation.reinvite_user @user.id
diff --git a/app/controllers/work_packages/bulk_controller.rb b/app/controllers/work_packages/bulk_controller.rb
index 070a31b3911..cfc4c9cffec 100644
--- a/app/controllers/work_packages/bulk_controller.rb
+++ b/app/controllers/work_packages/bulk_controller.rb
@@ -35,7 +35,6 @@ class WorkPackages::BulkController < ApplicationController
include CustomFieldsHelper
include RelationsHelper
include QueriesHelper
- include IssuesHelper
def edit
setup_edit
@@ -57,28 +56,25 @@ class WorkPackages::BulkController < ApplicationController
end
def destroy
- unless WorkPackage.cleanup_associated_before_destructing_if_required(@work_packages, current_user, params[:to_do])
+ if WorkPackage.cleanup_associated_before_destructing_if_required(@work_packages, current_user, params[:to_do])
+ destroy_work_packages(@work_packages)
respond_to do |format|
format.html do
- render locals: { work_packages: @work_packages,
- associated: WorkPackage.associated_classes_to_address_before_destruction_of(@work_packages) }
+ redirect_back_or_default(project_work_packages_path(@work_packages.first.project))
end
format.json do
- render json: { error_message: 'Clean up of associated objects required' }, status: 420
+ head :ok
end
end
-
else
-
- destroy_work_packages(@work_packages)
-
respond_to do |format|
format.html do
- redirect_back_or_default(project_work_packages_path(@work_packages.first.project))
+ render locals: { work_packages: @work_packages,
+ associated: WorkPackage.associated_classes_to_address_before_destruction_of(@work_packages) }
end
format.json do
- head :ok
+ render json: { error_message: 'Clean up of associated objects required' }, status: 420
end
end
end
@@ -87,24 +83,28 @@ class WorkPackages::BulkController < ApplicationController
private
def setup_edit
- @available_statuses = @projects.map { |p| Workflow.available_statuses(p) }.inject { |memo, w| memo & w }
- @custom_fields = @projects.map(&:all_work_package_custom_fields).inject { |memo, c| memo & c }
- @assignables = @projects.map(&:possible_assignees).inject { |memo, a| memo & a }
- @responsibles = @projects.map(&:possible_responsibles).inject { |memo, a| memo & a }
- @types = @projects.map(&:types).inject { |memo, t| memo & t }
+ @available_statuses = @projects.map { |p| Workflow.available_statuses(p) }.inject(&:&)
+ @custom_fields = @projects.map(&:all_work_package_custom_fields).inject(&:&)
+ @assignables = possible_assignees
+ @responsibles = @assignables
+ @types = @projects.map(&:types).inject(&:&)
end
def destroy_work_packages(work_packages)
work_packages.each do |work_package|
- begin
- WorkPackages::DeleteService
- .new(user: current_user,
- model: work_package.reload)
- .call
- rescue ::ActiveRecord::RecordNotFound
- # raised by #reload if work package no longer exists
- # nothing to do, work package was already deleted (eg. by a parent)
- end
+ WorkPackages::DeleteService
+ .new(user: current_user,
+ model: work_package.reload)
+ .call
+ rescue ::ActiveRecord::RecordNotFound
+ # raised by #reload if work package no longer exists
+ # nothing to do, work package was already deleted (eg. by a parent)
+ end
+ end
+
+ def possible_assignees
+ @projects.inject(Principal.all) do |scope, project|
+ scope.where(id: Principal.possible_assignee(project))
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 4777852ed6c..e2f98a3bb9b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -86,11 +86,11 @@ module ApplicationHelper
# returns a class name based on the user's status
def user_status_class(user)
- 'status_' + user.status_name
+ 'status_' + user.status
end
def user_status_i18n(user)
- t "status_#{user.status_name}"
+ t "status_#{user.status}"
end
def delete_link(url, options = {})
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
deleted file mode 100644
index f936d3ef82d..00000000000
--- a/app/helpers/issues_helper.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-#-- encoding: UTF-8
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See docs/COPYRIGHT.rdoc for more details.
-#++
-
-module IssuesHelper
- include ApplicationHelper
-
- # Renders a HTML/CSS tooltip
- #
- # To use, a trigger div is needed. This is a div with the class of "tooltip"
- # that contains this method wrapped in a span with the class of "tip"
- #
- # <div class="tooltip"><%= link_to_issue(issue) %>
- # <span class="tip"><%= render_issue_tooltip(issue) %></span>
- # </div>
- #
- def render_issue_tooltip(issue)
- @cached_label_status ||= WorkPackage.human_attribute_name(:status)
- @cached_label_start_date ||= WorkPackage.human_attribute_name(:start_date)
- @cached_label_due_date ||= WorkPackage.human_attribute_name(:due_date)
- @cached_label_assigned_to ||= WorkPackage.human_attribute_name(:assigned_to)
- @cached_label_priority ||= WorkPackage.human_attribute_name(:priority)
- @cached_label_project ||= WorkPackage.human_attribute_name(:project)
-
- (link_to_work_package(issue) + "<br /><br />
- <strong>#{@cached_label_project}</strong>: #{link_to_project(issue.project)}<br />
- <strong>#{@cached_label_status}</strong>: #{h(issue.status.name)}<br />
- <strong>#{@cached_label_start_date}</strong>: #{format_date(issue.start_date)}<br />
- <strong>#{@cached_label_due_date}</strong>: #{format_date(issue.due_date)}<br />
- <strong>#{@cached_label_assigned_to}</strong>: #{h(issue.assigned_to)}<br />
- <strong>#{@cached_label_priority}</strong>: #{h(issue.priority.name)}".html_safe)
- end
-
- def last_issue_note(issue)
- note_journals = issue.journals.select(&:notes?)
- return t(:text_no_notes) if note_journals.empty?
- note_journals.last.notes
- end
-end
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index c5f24279c57..5fb3f9908df 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -52,7 +52,7 @@ module UsersHelper
def full_user_status(user, include_num_failed_logins = false)
user_status = ''
unless user.active?
- user_status = translate_user_status(user.status_name)
+ user_status = translate_user_status(user.status)
end
brute_force_status = ''
if user.failed_too_many_recent_login_attempts?
@@ -88,7 +88,7 @@ module UsersHelper
# Create buttons to lock/unlock a user and reset failed logins
def build_change_user_status_action(user)
- status = user.status_name.to_sym
+ status = user.status.to_sym
blocked = !!user.failed_too_many_recent_login_attempts?
result = ''.html_safe
diff --git a/app/helpers/work_packages_helper.rb b/app/helpers/work_packages_helper.rb
index 52db9f5b892..3e2fddd4fad 100644
--- a/app/helpers/work_packages_helper.rb
+++ b/app/helpers/work_packages_helper.rb
@@ -212,6 +212,12 @@ module WorkPackagesHelper
route[:controller] == 'work_packages' && route[:action] == 'index' && route[:state]&.match?(/^\d+/)
end
+ def last_work_package_note(work_package)
+ note_journals = work_package.journals.select(&:notes?)
+ return t(:text_no_notes) if note_journals.empty?
+ note_journals.last.notes
+ end
+
private
def truncated_work_package_description(work_package, lines = 3)
diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb
index 1d6e967df71..2ba532321de 100644
--- a/app/mailers/base_mailer.rb
+++ b/app/mailers/base_mailer.rb
@@ -31,7 +31,6 @@ class BaseMailer < ActionMailer::Base
helper :application, # for format_text
:work_packages, # for css classes
:custom_fields # for show_value
- helper IssuesHelper
include OpenProject::LocaleHelper
diff --git a/app/models/custom_actions/actions/assigned_to.rb b/app/models/custom_actions/actions/assigned_to.rb
index 1ea7580d9b7..ea4f16a3ca2 100644
--- a/app/models/custom_actions/actions/assigned_to.rb
+++ b/app/models/custom_actions/actions/assigned_to.rb
@@ -53,7 +53,7 @@ class CustomActions::Actions::AssignedTo < CustomActions::Actions::Base
def available_principles
principal_class
- .active_or_registered
+ .not_locked
.select(:id, :firstname, :lastname, :type)
.order_by_name
.map { |u| [u.id, u.name] }
diff --git a/app/models/custom_actions/actions/notify.rb b/app/models/custom_actions/actions/notify.rb
index 64c085092fd..63c7045ae34 100644
--- a/app/models/custom_actions/actions/notify.rb
+++ b/app/models/custom_actions/actions/notify.rb
@@ -62,7 +62,7 @@ class CustomActions::Actions::Notify < CustomActions::Actions::Base
def principals
Principal
- .active_or_registered
+ .not_locked
.select(:id, :firstname, :lastname, :type)
.order_by_name
end
diff --git a/app/models/custom_actions/actions/responsible.rb b/app/models/custom_actions/actions/responsible.rb
index ce456e919b1..5b62d94d8b6 100644
--- a/app/models/custom_actions/actions/responsible.rb
+++ b/app/models/custom_actions/actions/responsible.rb
@@ -31,7 +31,7 @@ class CustomActions::Actions::Responsible < CustomActions::Actions::Base
def associated
User
- .active_or_registered
+ .not_locked
.select(:id, :firstname, :lastname, :type)
.order_by_name
.map { |u| [u.id, u.name] }
diff --git a/app/models/deleted_user.rb b/app/models/deleted_user.rb
index 2dfb7d3b1eb..bdc89365e3d 100644
--- a/app/models/deleted_user.rb
+++ b/app/models/deleted_user.rb
@@ -7,7 +7,7 @@ class DeletedUser < User
end
def self.first
- super || create(type: to_s, status: STATUSES[:locked])
+ super || create(type: to_s, status: statuses[:locked])
end
# Overrides a few properties
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index ec440d99112..537e538d120 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -481,9 +481,9 @@ class MailHandler < ActionMailer::Base
end
end
- def find_assignee_from_keyword(keyword, issue)
+ def find_assignee_from_keyword(keyword, work_package)
keyword = keyword.to_s.downcase
- assignable = issue.assignable_assignees
+ assignable = Principal.possible_assignee(work_package.project)
assignee = nil
assignee ||= assignable.detect do |a|
[a.mail.to_s.downcase, a.login.to_s.downcase].include?(keyword)
diff --git a/app/models/members/scopes/not_locked.rb b/app/models/members/scopes/not_locked.rb
index ae44bf82cfd..bca7c9ad71f 100644
--- a/app/models/members/scopes/not_locked.rb
+++ b/app/models/members/scopes/not_locked.rb
@@ -28,14 +28,14 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-# Find all members that are whose principals are not locked.
+# Find all members whose principals are not locked.
module Members::Scopes
class NotLocked
def self.fetch
Member
.includes(:principal)
.references(:principals)
- .merge(Principal.not_builtin_but_with_placeholder_users.active_or_registered)
+ .merge(Principal.not_locked, rewhere: true)
end
end
end
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 505ef5bf14c..2ef1e313a75 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -29,9 +29,10 @@
#++
class Principal < ApplicationRecord
+ include ::Scopes::Scoped
+
# Account statuses
- # Code accessing the keys assumes they are ordered, which they are since Ruby 1.9
- STATUSES = {
+ enum status: {
active: 1,
registered: 2,
locked: 3,
@@ -56,14 +57,17 @@ class Principal < ApplicationRecord
has_many :projects, through: :memberships
has_many :categories, foreign_key: 'assigned_to_id', dependent: :nullify
- scope :active, -> { where(status: STATUSES[:active]) }
+ scope_classes Principals::Scopes::NotBuiltin,
+ Principals::Scopes::User,
+ Principals::Scopes::Human,
+ Principals::Scopes::Like,
+ Principals::Scopes::PossibleMember,
+ Principals::Scopes::PossibleAssignee
- scope :active_or_registered, -> {
- not_builtin.where(status: [STATUSES[:active], STATUSES[:registered], STATUSES[:invited]])
+ scope :not_locked, -> {
+ not_builtin.where.not(status: statuses[:locked])
}
- scope :active_or_registered_like, ->(query) { active_or_registered.like(query) }
-
scope :in_project, ->(project) {
where(id: Member.of(project).select(:user_id))
}
@@ -72,48 +76,14 @@ class Principal < ApplicationRecord
where.not(id: Member.of(project).select(:user_id))
}
- scope :not_builtin, -> {
- # TODO: Remove PlaceholderUser from this list. This is a temporary hack that ensures that Placeholders don't
- # suddenly show up where they are are not supposed to show up. In case you want them to show up use the temporary
- # scope :not_builtin_but_with_placeholder_users
- where.not(type: [SystemUser.name, AnonymousUser.name, DeletedUser.name, PlaceholderUser.name])
- }
-
- scope :not_builtin_but_with_placeholder_users, -> {
- # TODO: This is temporary precaution scope to circumvent the hack in the :not_builtin scope. Needs to be
- # removed before we release this code.
- where.not(type: [SystemUser.name, AnonymousUser.name, DeletedUser.name])
- }
- OpenProject::Deprecation.deprecate_class_method self,
- :not_builtin_but_with_placeholder_users,
- :not_builtin
-
- scope :like, ->(q) {
- firstnamelastname = "((firstname || ' ') || lastname)"
- lastnamefirstname = "((lastname || ' ') || firstname)"
-
- s = "%#{q.to_s.downcase.strip.tr(',', '')}%"
-
- where(['LOWER(login) LIKE :s OR ' +
- "LOWER(#{firstnamelastname}) LIKE :s OR " +
- "LOWER(#{lastnamefirstname}) LIKE :s OR " +
- 'LOWER(mail) LIKE :s',
- { s: s }])
- .order(:type, :login, :lastname, :firstname, :mail)
- }
-
before_create :set_default_empty_values
def name(_formatter = nil)
to_s
end
- def self.possible_members(criteria, limit)
- Principal.active_or_registered_like(criteria).limit(limit)
- end
-
def self.search_scope_without_project(project, query)
- active_or_registered_like(query).not_in_project(project)
+ not_locked.like(query).not_in_project(project)
end
def self.order_by_name
@@ -133,20 +103,6 @@ class Principal < ApplicationRecord
.or(me)
end
- def status_name
- # Only Users should have another status than active.
- # User defines the status values and other classes like Principal
- # shouldn't know anything about them. Nevertheless, some functions
- # want to know the status for other Principals than User.
- raise 'Principal has status other than active' unless status == STATUSES[:active]
-
- 'active'
- end
-
- def active_or_registered?
- [STATUSES[:active], STATUSES[:registered], STATUSES[:invited]].include?(status)
- end
-
# Helper method to identify internal users
def builtin?
false
@@ -177,6 +133,19 @@ class Principal < ApplicationRecord
end
end
+ class << self
+ # Hack to exclude the Users::InexistentUser
+ # from showing up on filters for type.
+ # The method is copied over from rails changed only
+ # by the #compact call.
+ def type_condition(table = arel_table)
+ sti_column = table[inheritance_column]
+ sti_names = ([self] + descendants).map(&:sti_name).compact
+
+ predicate_builder.build(sti_column, sti_names)
+ end
+ end
+
protected
# Make sure we don't try to insert NULL values (see #4632)
diff --git a/app/models/principals/scopes/human.rb b/app/models/principals/scopes/human.rb
new file mode 100644
index 00000000000..deb8cd9eee6
--- /dev/null
+++ b/app/models/principals/scopes/human.rb
@@ -0,0 +1,42 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+# Only return Principals that are, direct or indirect humans.
+# Includes
+# * User
+# * Group
+module Principals::Scopes
+ class Human
+ def self.fetch
+ Principal.where(type: [::User.name,
+ Group.name])
+ end
+ end
+end
diff --git a/app/models/principals/scopes/like.rb b/app/models/principals/scopes/like.rb
new file mode 100644
index 00000000000..0fe8da8ace0
--- /dev/null
+++ b/app/models/principals/scopes/like.rb
@@ -0,0 +1,53 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+# Returns principals whose
+# * login
+# * firstname
+# * lastname
+# matches the provided string
+module Principals::Scopes
+ class Like
+ def self.fetch(search_string)
+ firstnamelastname = "((firstname || ' ') || lastname)"
+ lastnamefirstname = "((lastname || ' ') || firstname)"
+
+ s = "%#{search_string.to_s.downcase.strip.tr(',', '')}%"
+
+ Principal
+ .where(['LOWER(login) LIKE :s OR ' +
+ "LOWER(#{firstnamelastname}) LIKE :s OR " +
+ "LOWER(#{lastnamefirstname}) LIKE :s OR " +
+ 'LOWER(mail) LIKE :s',
+ { s: s }])
+ .order(:type, :login, :lastname, :firstname, :mail)
+ end
+ end
+end
diff --git a/app/models/principals/scopes/not_builtin.rb b/app/models/principals/scopes/not_builtin.rb
new file mode 100644
index 00000000000..56b8820d1da
--- /dev/null
+++ b/app/models/principals/scopes/not_builtin.rb
@@ -0,0 +1,45 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+# Only return Principals that are not built into the system so only return those that where
+# created by a human.
+# Excludes
+# * DeletedUser
+# * SystemUser
+# * AnonymousUser
+module Principals::Scopes
+ class NotBuiltin
+ def self.fetch
+ Principal.where.not(type: [SystemUser.name,
+ AnonymousUser.name,
+ DeletedUser.name])
+ end
+ end
+end
diff --git a/app/models/principals/scopes/possible_assignee.rb b/app/models/principals/scopes/possible_assignee.rb
new file mode 100644
index 00000000000..7a5d9336a27
--- /dev/null
+++ b/app/models/principals/scopes/possible_assignee.rb
@@ -0,0 +1,52 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Principals::Scopes
+ class PossibleAssignee
+ # Returns principals eligible to be assigned to a work package as:
+ # * assignee
+ # * responsible
+ # Those principals can be of class
+ # * User
+ # * PlaceholderUser
+ # * Group
+ # User instances need to be non locked (status).
+ # Only principals with a role marked as assignable in the project are returned.
+ # @project [Project] The project for which eligible candidates are to be searched
+ # @return [ActiveRecord::Relation] A scope of eligible candidates
+ def self.fetch(project)
+ Principal
+ .not_locked
+ .includes(:members)
+ .references(:members)
+ .merge(Member.assignable.of(project))
+ end
+ end
+end
diff --git a/app/models/principals/scopes/possible_member.rb b/app/models/principals/scopes/possible_member.rb
new file mode 100644
index 00000000000..bc82646f828
--- /dev/null
+++ b/app/models/principals/scopes/possible_member.rb
@@ -0,0 +1,49 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Principals::Scopes
+ class PossibleMember
+ # Returns principals eligible to become project members. Those principals can be of class
+ # * User
+ # * PlaceholderUser
+ # * Group
+ # User instances need to be non locked (status)
+ # Principals which already are project members are are returned.
+ # @project [Project] The project for which eligible candidates are to be searched
+ # @return [ActiveRecord::Relation] A scope of eligible candidates
+ def self.fetch(project)
+ Queries::Principals::PrincipalQuery
+ .new(user: ::User.current)
+ .where(:member, '!', [project.id])
+ .where(:status, '!', [Principal.statuses[:locked]])
+ .results
+ end
+ end
+end
diff --git a/app/models/principals/scopes/user.rb b/app/models/principals/scopes/user.rb
new file mode 100644
index 00000000000..6d27af770c2
--- /dev/null
+++ b/app/models/principals/scopes/user.rb
@@ -0,0 +1,40 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+# Only return Principals that are of type User
+module Principals::Scopes
+ class User
+ def self.fetch
+ # Have to use the User model here so that the scopes defined on User
+ # are also available after the scope is used.
+ ::User.where(type: [::User.name])
+ end
+ end
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 9c087501747..62554f65276 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -42,59 +42,14 @@ class Project < ApplicationRecord
# reserved identifiers
RESERVED_IDENTIFIERS = %w(new).freeze
- # TODO: Is this association ever used? Groups are missing (and PlaceholderUsers).
has_many :members, -> {
+ # TODO: check whether this should
+ # remaint to be limited to User only
includes(:principal, :roles)
- .where(
- "#{Principal.table_name}.type='User' AND (
- #{User.table_name}.status=#{Principal::STATUSES[:active]} OR
- #{User.table_name}.status=#{Principal::STATUSES[:invited]}
- )"
- )
+ .merge(Principal.not_locked.user)
.references(:principal, :roles)
}
- has_many :possible_assignee_members,
- -> { assignable },
- class_name: 'Member'
-
- # Read only
- has_many :possible_assignees,
- ->(object) {
- # Have to reference members and roles again although
- # possible_assignee_members does already specify it to be able to use the
- # assignable_principals there
- #
- # The .where(members_users: { project_id: object.id })
- # part is an optimization preventing to have all the members joined
- includes(members: :roles)
- .where(members_users: { project_id: object.id })
- .references(:roles)
- .merge(Principal.order_by_name)
- },
- through: :possible_assignee_members,
- source: :principal
-
- has_many :possible_responsible_members,
- -> { assignable },
- class_name: 'Member'
-
- # Read only
- has_many :possible_responsibles,
- ->(object) {
- # Have to reference members and roles again although
- # possible_responsible_members does already specify it to be able to use
- # assignable_principals there
- #
- # The .where(members_users: { project_id: object.id })
- # part is an optimization preventing to have all the members joined
- includes(members: :roles)
- .where(members_users: { project_id: object.id })
- .references(:roles)
- .merge(Principal.order_by_name)
- },
- through: :possible_responsible_members,
- source: :principal
has_many :memberships, class_name: 'Member'
has_many :member_principals,
-> { not_locked },
@@ -203,10 +158,6 @@ class Project < ApplicationRecord
visible.like(query)
end
- def possible_members(criteria, limit)
- Principal.active_or_registered.like(criteria).not_in_project(self).limit(limit)
- end
-
def add_member(user, roles)
members.build.tap do |m|
m.principal = user
diff --git a/app/models/queries/filters/shared/user_status_filter.rb b/app/models/queries/filters/shared/user_status_filter.rb
index 49174bd267f..a5b80cf3a30 100644
--- a/app/models/queries/filters/shared/user_status_filter.rb
+++ b/app/models/queries/filters/shared/user_status_filter.rb
@@ -36,7 +36,7 @@ module Queries::Filters::Shared::UserStatusFilter
module InstanceMethods
def allowed_values
- Principal::STATUSES.keys.map do |key|
+ Principal.statuses.keys.map do |key|
[I18n.t(:"status_#{key}"), key]
end
end
@@ -46,7 +46,7 @@ module Queries::Filters::Shared::UserStatusFilter
end
def status_values
- values.map { |value| Principal::STATUSES[value.to_sym] }
+ values.map { |value| Principal.statuses[value.to_sym] }
end
def where
diff --git a/app/models/queries/members/filters/principal_filter.rb b/app/models/queries/members/filters/principal_filter.rb
index 03f67958fa4..1d1dc60eb2a 100644
--- a/app/models/queries/members/filters/principal_filter.rb
+++ b/app/models/queries/members/filters/principal_filter.rb
@@ -34,7 +34,7 @@ class Queries::Members::Filters::PrincipalFilter < Queries::Members::Filters::Me
def allowed_values
@allowed_values ||= begin
values = Principal
- .active_or_registered
+ .not_locked
.in_visible_project_or_me
.map { |s| [s.name, s.id.to_s] }
.sort
diff --git a/app/models/queries/principals/filters/member_filter.rb b/app/models/queries/principals/filters/member_filter.rb
index 90f8f8332e7..b7ad70d3130 100644
--- a/app/models/queries/principals/filters/member_filter.rb
+++ b/app/models/queries/principals/filters/member_filter.rb
@@ -50,6 +50,7 @@ class Queries::Principals::Filters::MemberFilter < Queries::Principals::Filters:
default_scope.where(members: { project_id: values })
when '!'
default_scope.where.not(members: { project_id: values })
+ .or(default_scope.where(members: { project_id: nil }))
when '*'
default_scope.where.not(members: { project_id: nil })
when '!*'
diff --git a/app/models/queries/principals/filters/status_filter.rb b/app/models/queries/principals/filters/status_filter.rb
index 29020539bab..124f320af3d 100644
--- a/app/models/queries/principals/filters/status_filter.rb
+++ b/app/models/queries/principals/filters/status_filter.rb
@@ -29,7 +29,7 @@
class Queries::Principals::Filters::StatusFilter < Queries::Principals::Filters::PrincipalFilter
def allowed_values
- ::Principal::STATUSES.map do |key, value|
+ ::Principal.statuses.map do |key, value|
[key, value]
end
end
diff --git a/app/models/queries/principals/filters/type_filter.rb b/app/models/queries/principals/filters/type_filter.rb
index a59e9070c58..ade893ba0c2 100644
--- a/app/models/queries/principals/filters/type_filter.rb
+++ b/app/models/queries/principals/filters/type_filter.rb
@@ -29,8 +29,8 @@
class Queries::Principals::Filters::TypeFilter < Queries::Principals::Filters::PrincipalFilter
def allowed_values
- [[Group.to_s, Group.to_s],
- [User.to_s, User.to_s]]
+ [User, Group, PlaceholderUser]
+ .map { |x| [x.to_s, x.to_s] }
end
def type
diff --git a/app/models/queries/users/filters/user_filter.rb b/app/models/queries/users/filters/user_filter.rb
index e850abab13b..df33f9c2f84 100644
--- a/app/models/queries/users/filters/user_filter.rb
+++ b/app/models/queries/users/filters/user_filter.rb
@@ -28,7 +28,7 @@
#++
class Queries::Users::Filters::UserFilter < Queries::Filters::Base
- self.model = User
+ self.model = User.user
def human_name
User.human_attribute_name(name)
diff --git a/app/models/queries/users/user_query.rb b/app/models/queries/users/user_query.rb
index a730d399f84..8f8474d9931 100644
--- a/app/models/queries/users/user_query.rb
+++ b/app/models/queries/users/user_query.rb
@@ -32,6 +32,11 @@ class Queries::Users::UserQuery < Queries::BaseQuery
end
def default_scope
- User.not_builtin
+ # This seemingly duplication is necessary because of the builtin classes
+ # * SystemUser
+ # * DeletedUser
+ # * AnonymousUser
+ # inheriting from user. Without it, instances of those classes would show up.
+ User.user
end
end
diff --git a/app/models/queries/work_packages/filter/principal_loader.rb b/app/models/queries/work_packages/filter/principal_loader.rb
index 77d05aa617d..3fee0168952 100644
--- a/app/models/queries/work_packages/filter/principal_loader.rb
+++ b/app/models/queries/work_packages/filter/principal_loader.rb
@@ -55,7 +55,7 @@ class Queries::WorkPackages::Filter::PrincipalLoader
if project
project.principals.sort
else
- Principal.active_or_registered.in_visible_project.sort
+ Principal.not_locked.in_visible_project.sort
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index da158eefbc6..9146f6bca75 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -31,8 +31,6 @@
require 'digest/sha1'
class User < Principal
- include ::Scopes::Scoped
-
USER_FORMATS_STRUCTURE = {
firstname_lastname: [:firstname, :lastname],
firstname: [:firstname],
@@ -58,6 +56,7 @@ class User < Principal
].freeze
include ::Associations::Groupable
+ extend DeprecatedAlias
has_many :categories, foreign_key: 'assigned_to_id',
dependent: :nullify
@@ -88,7 +87,8 @@ class User < Principal
scope :blocked, -> { create_blocked_scope(self, true) }
scope :not_blocked, -> { create_blocked_scope(self, false) }
- scope_classes Users::Scopes::FindByLogin
+ scope_classes Users::Scopes::FindByLogin,
+ Users::Scopes::Newest
def self.create_blocked_scope(scope, blocked)
scope.where(blocked_condition(blocked))
@@ -160,8 +160,6 @@ class User < Principal
scope :admin, -> { where(admin: true) }
- scope :newest, -> { not_builtin.order(created_at: :desc) }
-
def self.unique_attribute
:login
end
@@ -318,23 +316,8 @@ class User < Principal
# Return user's authentication provider for display
def authentication_provider
return if identity_url.blank?
- identity_url.split(':', 2).first.titleize
- end
-
- def status_name
- STATUSES.invert[status].to_s
- end
-
- def active?
- status == STATUSES[:active]
- end
-
- def registered?
- status == STATUSES[:registered]
- end
- def locked?
- status == STATUSES[:locked]
+ identity_url.split(':', 2).first.titleize
end
##
@@ -347,40 +330,25 @@ class User < Principal
alias_method :activatable?, :locked?
def activate
- self.status = STATUSES[:active]
+ self.status = self.class.statuses[:active]
end
def register
- self.status = STATUSES[:registered]
+ self.status = self.class.statuses[:registered]
end
def invite
- self.status = STATUSES[:invited]
+ self.status = self.class.statuses[:invited]
end
def lock
- self.status = STATUSES[:locked]
- end
-
- def activate!
- update_attribute(:status, STATUSES[:active])
- end
-
- def register!
- update_attribute(:status, STATUSES[:registered])
+ self.status = self.class.statuses[:locked]
end
- def invite!
- update_attribute(:status, STATUSES[:invited])
- end
-
- def invited?
- status == STATUSES[:invited]
- end
-
- def lock!
- update_attribute(:status, STATUSES[:locked])
- end
+ deprecated_alias :activate!, :active!
+ deprecated_alias :register!, :registered!
+ deprecated_alias :invite!, :invited!
+ deprecated_alias :lock!, :locked!
# Returns true if +clear_password+ is the correct user's password, otherwise false
# If +update_legacy+ is set, will automatically save legacy passwords using the current
@@ -689,7 +657,7 @@ class User < Principal
u.login = ''
u.firstname = ''
u.mail = ''
- u.status = User::STATUSES[:active]
+ u.status = User.statuses[:active]
end).save
raise 'Unable to create the anonymous user.' if anonymous_user.new_record?
end
@@ -707,7 +675,7 @@ class User < Principal
login: "",
mail: "",
admin: false,
- status: User::STATUSES[:active],
+ status: User.statuses[:active],
first_login: false
)
diff --git a/app/models/users/inexistent_user.rb b/app/models/users/inexistent_user.rb
index 8e25fa6f74b..747a11e879c 100644
--- a/app/models/users/inexistent_user.rb
+++ b/app/models/users/inexistent_user.rb
@@ -28,4 +28,8 @@
# See docs/COPYRIGHT.rdoc for more details.
#++
-class Users::InexistentUser < User; end
+class Users::InexistentUser < User
+ def self.sti_name
+ nil
+ end
+end
diff --git a/app/models/users/scopes/newest.rb b/app/models/users/scopes/newest.rb
new file mode 100644
index 00000000000..c3614590bc1
--- /dev/null
+++ b/app/models/users/scopes/newest.rb
@@ -0,0 +1,39 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+# Returns users sorted by their creation date. Inheriting classes are
+# excluded.
+module Users::Scopes
+ class Newest
+ def self.fetch
+ User.user.order(created_at: :desc)
+ end
+ end
+end
diff --git a/app/models/users/status_options.rb b/app/models/users/status_options.rb
index eca759845fe..c9eb5c94bfd 100644
--- a/app/models/users/status_options.rb
+++ b/app/models/users/status_options.rb
@@ -14,18 +14,18 @@ module Users
end
def user_count_by_status(extra: {})
- counts = User.not_builtin.group(:status).count.to_hash
+ counts = User.user.group(:status).count.to_hash
counts
.merge(symbolic_user_counts)
.merge(extra)
.reject { |_, v| v.nil? } # remove nil counts to support dropping counts via extra
.map do |k, v|
- known_status = Principal::STATUSES.detect { |_, i| i == k }
+ known_status = Principal.statuses.detect { |_, i| i == k }
if known_status
- [known_status.first, v]
+ [known_status.first.to_sym, v]
else
- [k, v]
+ [k.to_sym, v]
end
end
.to_h
@@ -33,9 +33,9 @@ module Users
def symbolic_user_counts
{
- blocked: User.not_builtin.blocked.count, # not_builtin to skip DeletedUser
- all: User.not_builtin.count,
- active: User.not_builtin.active.not_blocked.count # not_builtin to skip Anonymous and System users
+ blocked: User.user.blocked.count, # User.user scope to skip DeletedUser
+ all: User.user.count,
+ active: User.user.active.not_blocked.count # User.user to skip Anonymous and System users
}
end
end
diff --git a/app/models/watcher.rb b/app/models/watcher.rb
index 596e280f62e..5314a43e950 100644
--- a/app/models/watcher.rb
+++ b/app/models/watcher.rb
@@ -50,7 +50,8 @@ class Watcher < ApplicationRecord
def validate_active_user
# TODO add informative error message
return if user.blank?
- errors.add :user_id, :invalid unless user.active_or_registered?
+
+ errors.add :user_id, :invalid if user.locked?
end
def validate_user_allowed_to_watch
diff --git a/app/models/work_package.rb b/app/models/work_package.rb
index dd8988b3445..e9f159cd38b 100644
--- a/app/models/work_package.rb
+++ b/app/models/work_package.rb
@@ -254,16 +254,6 @@ class WorkPackage < ApplicationRecord
time_entries.build(attributes)
end
- # Users/groups the work_package can be assigned to
- def assignable_assignees
- project.possible_assignees
- end
-
- # Users the work_package can be assigned to
- def assignable_responsibles
- project.possible_responsibles
- end
-
# Versions that the work_package can be assigned to
# A work_package can be assigned to:
# * any open, shared version of the project the wp belongs to
diff --git a/app/seeders/admin_user_seeder.rb b/app/seeders/admin_user_seeder.rb
index c0b47fc2487..60014a18fc3 100644
--- a/app/seeders/admin_user_seeder.rb
+++ b/app/seeders/admin_user_seeder.rb
@@ -55,7 +55,7 @@ class AdminUserSeeder < Seeder
user.mail = ENV['ADMIN_EMAIL'].presence || '[email protected]'
user.mail_notification = User::USER_MAIL_OPTION_ONLY_MY_EVENTS.first
user.language = I18n.locale.to_s
- user.status = User::STATUSES[:active]
+ user.status = User.statuses[:active]
user.force_password_change = force_password_change?
end
end
diff --git a/app/seeders/development_data/users_seeder.rb b/app/seeders/development_data/users_seeder.rb
index 0a1abf27849..4b729119036 100644
--- a/app/seeders/development_data/users_seeder.rb
+++ b/app/seeders/development_data/users_seeder.rb
@@ -102,7 +102,7 @@ module DevelopmentData
user.firstname = login.humanize
user.lastname = 'DEV user'
user.mail = "#{login}@example.net"
- user.status = User::STATUSES[:active]
+ user.status = User.statuses[:active]
user.language = I18n.locale
user.force_password_change = false
end
diff --git a/app/services/authorization/user_allowed_service.rb b/app/services/authorization/user_allowed_service.rb
index 8215e5f97e8..04b51e5df31 100644
--- a/app/services/authorization/user_allowed_service.rb
+++ b/app/services/authorization/user_allowed_service.rb
@@ -113,7 +113,7 @@ class Authorization::UserAllowedService
# Only users that are not locked may be granted actions
# with the exception of a temporary-granted system user
def authorizable_user?
- user.active_or_registered? || user.is_a?(SystemUser)
+ !user.locked? || user.is_a?(SystemUser)
end
def has_authorized_role?(action, project = nil)
diff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rb
index 129a2bd3a1e..ef83604edda 100644
--- a/app/services/projects/copy/work_packages_dependent_service.rb
+++ b/app/services/projects/copy/work_packages_dependent_service.rb
@@ -153,19 +153,20 @@ module Projects::Copy
end
def work_package_assigned_to_id(source_work_package)
- assigned_to_id = source_work_package.assigned_to_id
- return unless assigned_to_id
-
- @assignees ||= target.possible_assignees.pluck(:id).to_set
- assigned_to_id if @assignees.include?(assigned_to_id)
+ possible_principal_id(source_work_package.assigned_to_id,
+ source_work_package.project)
end
def work_package_responsible_id(source_work_package)
- responsible_id = source_work_package.responsible_id
- return unless responsible_id
+ possible_principal_id(source_work_package.responsible_id,
+ source_work_package.project)
+ end
+
+ def possible_principal_id(principal_id, project)
+ return unless principal_id
- @responsible ||= target.possible_responsibles.pluck(:id).to_set
- responsible_id if @responsible.include?(responsible_id)
+ @principals ||= Principal.possible_assignee(project).pluck(:id).to_set
+ principal_id if @principals.include?(principal_id)
end
end
end
diff --git a/app/services/user_search_service.rb b/app/services/user_search_service.rb
index af26eddbbfa..28c087ff8d2 100644
--- a/app/services/user_search_service.rb
+++ b/app/services/user_search_service.rb
@@ -48,9 +48,9 @@ class UserSearchService
def scope
if users_only
- project.nil? ? User : project.users
+ project.nil? ? User : project.users.user
else
- project.nil? ? Principal : project.principals
+ project.nil? ? Principal : project.principals.human
end
end
@@ -61,22 +61,23 @@ class UserSearchService
def ids_search(scope)
ids = params[:ids].split(',')
- scope.not_builtin.where(id: ids)
+ scope.where(id: ids)
end
def query_search(scope)
scope = scope.in_group(params[:group_id].to_i) if params[:group_id].present?
c = ARCondition.new
- if params[:status] == 'blocked'
+ case params[:status]
+ when 'blocked'
@status = :blocked
scope = scope.blocked
- elsif params[:status] == 'all'
+ when 'all'
@status = :all
- scope = scope.not_builtin
+ # No scope change necessary
else
- @status = params[:status] ? params[:status].to_i : User::STATUSES[:active]
- scope = scope.not_blocked if users_only && @status == User::STATUSES[:active]
+ @status = params[:status] ? params[:status].to_i : User.statuses[:active]
+ scope = scope.not_blocked if users_only && @status == User.statuses[:active]
c << ['status = ?', @status]
end
diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb
index 73e63ef924e..686efe5d0d0 100644
--- a/app/views/categories/_form.html.erb
+++ b/app/views/categories/_form.html.erb
@@ -34,7 +34,7 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="form--field">
<%= f.select :assigned_to_id,
- @project.possible_assignees.sort.collect{|u| [u.name, u.id]},
+ Principal.possible_assignee(@project).order_by_name.collect{|u| [u.name, u.id]},
include_blank: true,
container_class: '-slim' %>
</div>
diff --git a/app/views/groups/_users.html.erb b/app/views/groups/_users.html.erb
index fdbc5b380e7..aa9d27ea3a3 100644
--- a/app/views/groups/_users.html.erb
+++ b/app/views/groups/_users.html.erb
@@ -43,7 +43,7 @@ See docs/COPYRIGHT.rdoc for more details.
<div class="grid-content medium-6 -visible-overflow">
<% users = User
- .not_builtin
+ .user
.active
.not_in_group(@group)
.limit(1) %>
diff --git a/app/views/user_mailer/work_package_watcher_changed.html.erb b/app/views/user_mailer/work_package_watcher_changed.html.erb
index fca70d26de4..c86ef7fa685 100644
--- a/app/views/user_mailer/work_package_watcher_changed.html.erb
+++ b/app/views/user_mailer/work_package_watcher_changed.html.erb
@@ -30,7 +30,7 @@ See docs/COPYRIGHT.rdoc for more details.
<hr />
<%= render partial: 'issue_details', locals: { issue: @issue } %>
<p>
- <%= format_text(t(:text_latest_note, note: last_issue_note(@issue)),
+ <%= format_text(t(:text_latest_note, note: last_work_package_note(@issue)),
only_path: false,
object: @issue,
project: @issue.project) %>
diff --git a/app/views/user_mailer/work_package_watcher_changed.text.erb b/app/views/user_mailer/work_package_watcher_changed.text.erb
index fade1d55f27..cadea894e71 100644
--- a/app/views/user_mailer/work_package_watcher_changed.text.erb
+++ b/app/views/user_mailer/work_package_watcher_changed.text.erb
@@ -31,4 +31,4 @@ See docs/COPYRIGHT.rdoc for more details.
----------------------------------------
<%= render partial: 'issue_details', locals: { issue: @issue } %>
-<%= t(:text_latest_note, note: last_issue_note(@issue)) %>
+<%= t(:text_latest_note, note: last_work_package_note(@issue)) %>
diff --git a/app/views/work_packages/moves/new.html.erb b/app/views/work_packages/moves/new.html.erb
index 42a0fb8dd1e..e934143f2e2 100644
--- a/app/views/work_packages/moves/new.html.erb
+++ b/app/views/work_packages/moves/new.html.erb
@@ -101,7 +101,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= styled_select_tag('assigned_to_id',
content_tag('option', t(:label_no_change_option), value: '') +
content_tag('option', t(:label_nobody), value: 'none') +
- options_from_collection_for_select(@target_project.possible_assignees, :id, :name)) %>
+ options_from_collection_for_select(Principal.possible_assignee(@target_project), :id, :name)) %>
</div>
</div>
<div class="form--field">
@@ -110,7 +110,7 @@ See docs/COPYRIGHT.rdoc for more details.
<%= styled_select_tag('responsible_id',
content_tag('option', t(:label_no_change_option), value: '') +
content_tag('option', t(:label_nobody), value: 'none') +
- options_from_collection_for_select(@target_project.possible_responsibles, :id, :name)) %>
+ options_from_collection_for_select(Principal.possible_assignee(@target_project), :id, :name)) %>
</div>
</div>
<div class="form--field">
diff --git a/db/migrate/20191106132533_make_system_user_active.rb b/db/migrate/20191106132533_make_system_user_active.rb
index f7729f5c674..00bab9467c1 100644
--- a/db/migrate/20191106132533_make_system_user_active.rb
+++ b/db/migrate/20191106132533_make_system_user_active.rb
@@ -3,12 +3,12 @@ class MakeSystemUserActive < ActiveRecord::Migration[6.0]
BUILTIN_STATUS ||= 0
def up
- Principal.where(status: BUILTIN_STATUS).update_all(status: Principal::STATUSES[:active])
+ Principal.where(status: BUILTIN_STATUS).update_all(status: Principal.statuses[:active])
end
def down
AnonymousUser.update_all(status: BUILTIN_STATUS)
DeletedUser.update_all(status: BUILTIN_STATUS)
- SystemUser.update_all(status: Principal::STATUSES[:locked])
+ SystemUser.update_all(status: Principal.statuses[:locked])
end
end
diff --git a/db/migrate/20191112111040_fix_system_user_status.rb b/db/migrate/20191112111040_fix_system_user_status.rb
index d5fbb246ed4..bfc5c2cd885 100644
--- a/db/migrate/20191112111040_fix_system_user_status.rb
+++ b/db/migrate/20191112111040_fix_system_user_status.rb
@@ -9,18 +9,18 @@ class FixSystemUserStatus < ActiveRecord::Migration[6.0]
# wrong status (0) because we failed to update the on-the-fly
# creation of the anonymous user with the correct status.
active_users.each do |user|
- user.update_all status: Principal::STATUSES[:active]
+ user.update_all status: Principal.statuses[:active]
end
- deleted_user.update_all status: Principal::STATUSES[:active]
+ deleted_user.update_all status: Principal.statuses[:active]
end
def down
# reset system user to locked which would've been the state before this migration
- system_user.update_all status: Principal::STATUSES[:locked]
+ system_user.update_all status: Principal.statuses[:locked]
# reset deleted usr to active which he would've been after the previous migration
- deleted_user.update_all status: Principal::STATUSES[:active]
+ deleted_user.update_all status: Principal.statuses[:active]
# There is no need to update the anonymous user since it was supposed to be
# active at this point already anyway. The previous migration then makes it
diff --git a/lib/api/v3/memberships/schemas/membership_schema_representer.rb b/lib/api/v3/memberships/schemas/membership_schema_representer.rb
index 5fe772619a7..c67a4596311 100644
--- a/lib/api/v3/memberships/schemas/membership_schema_representer.rb
+++ b/lib/api/v3/memberships/schemas/membership_schema_representer.rb
@@ -93,7 +93,7 @@ module API
end
def allowed_principals_filters
- statuses = [Principal::STATUSES[:locked].to_s]
+ statuses = [Principal.statuses[:locked].to_s]
status_filter = { status: { operator: '!', values: statuses } }
filters = [status_filter]
diff --git a/lib/api/v3/placeholder_users/placeholder_user_representer.rb b/lib/api/v3/placeholder_users/placeholder_user_representer.rb
new file mode 100644
index 00000000000..bc3e8f8a472
--- /dev/null
+++ b/lib/api/v3/placeholder_users/placeholder_user_representer.rb
@@ -0,0 +1,41 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+module API
+ module V3
+ module PlaceholderUsers
+ class PlaceholderUserRepresenter < ::API::V3::Principals::PrincipalRepresenter
+ def _type
+ 'PlaceholderUser'
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/v3/principals/associated_subclass_lambda.rb b/lib/api/v3/principals/associated_subclass_lambda.rb
index d1d504ffb86..b6b18ef03b5 100644
--- a/lib/api/v3/principals/associated_subclass_lambda.rb
+++ b/lib/api/v3/principals/associated_subclass_lambda.rb
@@ -43,6 +43,8 @@ module API
:user
when Group
:group
+ when PlaceholderUser
+ :placeholder_user
when NilClass
# Fall back to user for unknown principal
# since we do not have a principal route.
@@ -65,28 +67,32 @@ module API
instance = represented.send(name)
- case instance
- when User
- ::API::V3::Users::UserRepresenter.new(represented.send(name), current_user: current_user)
- when Group
- ::API::V3::Groups::GroupRepresenter.new(represented.send(name), current_user: current_user)
- when NilClass
- nil
- else
- raise "undefined subclass for #{instance}"
- end
+ representer = case instance
+ when User
+ ::API::V3::Users::UserRepresenter
+ when Group
+ ::API::V3::Groups::GroupRepresenter
+ when PlaceholderUser
+ ::API::V3::PlaceholderUsers::PlaceholderUserRepresenter
+ when NilClass
+ nil
+ else
+ raise "undefined subclass for #{instance}"
+ end
+
+ representer&.new(represented.send(name), current_user: current_user)
}
end
- def self.setter(name, property_name: name, namespaces: %i(groups users))
+ def self.setter(name, property_name: name, namespaces: %i(groups users placeholder_users))
->(fragment:, **) {
- link = ::API::Decorators::LinkObject.new(represented,
- property_name: property_name,
- namespace: namespaces,
- getter: :"#{name}_id",
- setter: :"#{name}_id=")
-
- link.from_hash(fragment)
+ ::API::Decorators::LinkObject
+ .new(represented,
+ property_name: property_name,
+ namespace: namespaces,
+ getter: :"#{name}_id",
+ setter: :"#{name}_id=")
+ .from_hash(fragment)
}
end
end
diff --git a/lib/api/v3/principals/group_or_user_elements.rb b/lib/api/v3/principals/not_builtin_elements.rb
similarity index 91%
rename from lib/api/v3/principals/group_or_user_elements.rb
rename to lib/api/v3/principals/not_builtin_elements.rb
index 57e64c65422..69ec94397a3 100644
--- a/lib/api/v3/principals/group_or_user_elements.rb
+++ b/lib/api/v3/principals/not_builtin_elements.rb
@@ -31,7 +31,7 @@
module API
module V3
module Principals
- module GroupOrUserElements
+ module NotBuiltinElements
extend ::ActiveSupport::Concern
included do
@@ -43,6 +43,8 @@ module API
::API::V3::Users::UserRepresenter
when Group
::API::V3::Groups::GroupRepresenter
+ when PlaceholderUser
+ ::API::V3::PlaceholderUsers::PlaceholderUserRepresenter
else
raise "unsupported type"
end
diff --git a/lib/api/v3/principals/principal_representer.rb b/lib/api/v3/principals/principal_representer.rb
index d3589f191bb..65e1d8cb6ed 100644
--- a/lib/api/v3/principals/principal_representer.rb
+++ b/lib/api/v3/principals/principal_representer.rb
@@ -80,8 +80,8 @@ module API
end
def current_user_allowed_to_see_members?
- current_user.allowed_to?(:view_members, nil, global: true) ||
- current_user.allowed_to?(:manage_members, nil, global: true)
+ current_user.allowed_to_globally?(:view_members) ||
+ current_user.allowed_to_globally?(:manage_members)
end
end
end
diff --git a/lib/api/v3/projects/available_assignees_api.rb b/lib/api/v3/projects/available_assignees_api.rb
index e45494b6bae..b9453848878 100644
--- a/lib/api/v3/projects/available_assignees_api.rb
+++ b/lib/api/v3/projects/available_assignees_api.rb
@@ -37,13 +37,12 @@ module API
authorize(:view_work_packages, global: true, user: current_user)
end
- get do
- available_assignees = @project.possible_assignees.includes(:preference)
- self_link = api_v3_paths.available_assignees(@project.id)
- Users::UserCollectionRepresenter.new(available_assignees,
- self_link: self_link,
- current_user: current_user)
- end
+ get &::API::V3::Utilities::Endpoints::Index.new(model: Principal,
+ scope: -> {
+ Principal.possible_assignee(@project).includes(:preference)
+ },
+ render_representer: Users::UserCollectionRepresenter)
+ .mount
end
end
end
diff --git a/lib/api/v3/projects/available_responsibles_api.rb b/lib/api/v3/projects/available_responsibles_api.rb
index af86617e59a..36402d7cdb9 100644
--- a/lib/api/v3/projects/available_responsibles_api.rb
+++ b/lib/api/v3/projects/available_responsibles_api.rb
@@ -37,13 +37,12 @@ module API
authorize(:view_work_packages, global: true, user: current_user)
end
- get do
- available_responsibles = @project.possible_responsibles.includes(:preference)
- self_link = api_v3_paths.available_responsibles(@project.id)
- Users::UserCollectionRepresenter.new(available_responsibles,
- self_link: self_link,
- current_user: current_user)
- end
+ get &::API::V3::Utilities::Endpoints::Index.new(model: Principal,
+ scope: -> {
+ Principal.possible_assignee(@project).includes(:preference)
+ },
+ render_representer: Users::UserCollectionRepresenter)
+ .mount
end
end
end
diff --git a/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb
index 9484cf274be..e6355a609bf 100644
--- a/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb
+++ b/lib/api/v3/queries/schemas/all_principals_filter_dependency_representer.rb
@@ -47,7 +47,7 @@ module API
def filter_query
params = [{ status: { operator: '!',
- values: [Principal::STATUSES[:locked].to_s] } }]
+ values: [Principal.statuses[:locked].to_s] } }]
params << if filter.project
{ member: { operator: '=', values: [filter.project.id.to_s] } }
diff --git a/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb b/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb
index 50a7f67a53d..6e63fe38bb5 100644
--- a/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb
+++ b/lib/api/v3/queries/schemas/user_filter_dependency_representer.rb
@@ -45,7 +45,7 @@ module API
params = [{ type: { operator: '=',
values: ['User'] } },
{ status: { operator: '!',
- values: [Principal::STATUSES[:locked].to_s] } }]
+ values: [Principal.statuses[:locked].to_s] } }]
if filter.project
params << { member: { operator: '=', values: [filter.project.id.to_s] } }
diff --git a/lib/api/v3/users/paginated_user_collection_representer.rb b/lib/api/v3/users/paginated_user_collection_representer.rb
index fd8ebfc84f5..5acb871b375 100644
--- a/lib/api/v3/users/paginated_user_collection_representer.rb
+++ b/lib/api/v3/users/paginated_user_collection_representer.rb
@@ -38,7 +38,7 @@ module API
module V3
module Users
class PaginatedUserCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection
- include API::V3::Principals::GroupOrUserElements
+ include API::V3::Principals::NotBuiltinElements
end
end
end
diff --git a/lib/api/v3/users/user_collection_representer.rb b/lib/api/v3/users/user_collection_representer.rb
index a58c646ef71..0118abacc47 100644
--- a/lib/api/v3/users/user_collection_representer.rb
+++ b/lib/api/v3/users/user_collection_representer.rb
@@ -31,7 +31,7 @@ module API
module V3
module Users
class UserCollectionRepresenter < ::API::Decorators::UnpaginatedCollection
- include API::V3::Principals::GroupOrUserElements
+ include API::V3::Principals::NotBuiltinElements
end
end
end
diff --git a/lib/api/v3/users/user_representer.rb b/lib/api/v3/users/user_representer.rb
index fe9bf6e7e95..9408de3a448 100644
--- a/lib/api/v3/users/user_representer.rb
+++ b/lib/api/v3/users/user_representer.rb
@@ -138,8 +138,8 @@ module API
render_nil: true
property :status,
- getter: ->(*) { status_name },
- setter: ->(fragment:, represented:, **) { represented.status = User::STATUSES[fragment.to_sym] },
+ getter: ->(*) { status },
+ setter: ->(fragment:, represented:, **) { represented.status = User.statuses[fragment.to_sym] },
render_nil: true,
cache_if: -> { current_user_is_admin_or_self }
diff --git a/lib/api/v3/utilities/custom_field_injector.rb b/lib/api/v3/utilities/custom_field_injector.rb
index 730663a443b..f5fe2bff140 100644
--- a/lib/api/v3/utilities/custom_field_injector.rb
+++ b/lib/api/v3/utilities/custom_field_injector.rb
@@ -362,7 +362,7 @@ module API
def allowed_users_static_filters
[{ status: { operator: '!',
- values: [Principal::STATUSES[:locked].to_s] } },
+ values: [Principal.statuses[:locked].to_s] } },
{ type: { operator: '=', values: ['User'] } }]
end
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 32d32174087..16a819bc79b 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -211,6 +211,9 @@ module API
"#{newses}/#{id}"
end
+ index :placeholder_user
+ show :placeholder_user
+
index :post
show :post
diff --git a/lib/api/v3/work_packages/principal_setter.rb b/lib/api/v3/work_packages/principal_setter.rb
index a3240c5a979..9f12aa88b8e 100644
--- a/lib/api/v3/work_packages/principal_setter.rb
+++ b/lib/api/v3/work_packages/principal_setter.rb
@@ -37,7 +37,7 @@ module API
lambda = ::API::V3::Principals::AssociatedSubclassLambda
.setter(name,
property_name: property_name,
- namespaces: %i(groups users))
+ namespaces: %i(groups users placeholder_users))
instance_exec(**args, &lambda)
}
diff --git a/lib/api/v3/work_packages/watchers_api.rb b/lib/api/v3/work_packages/watchers_api.rb
index e8639cb334a..43e26456537 100644
--- a/lib/api/v3/work_packages/watchers_api.rb
+++ b/lib/api/v3/work_packages/watchers_api.rb
@@ -57,7 +57,7 @@ module API
resources :watchers do
helpers do
def watchers_collection
- watchers = @work_package.watcher_users.active_or_registered
+ watchers = @work_package.watcher_users.merge(Principal.not_locked)
self_link = api_v3_paths.work_package_watchers(@work_package.id)
Users::UserCollectionRepresenter.new(watchers,
self_link: self_link,
diff --git a/lib/open_project/enterprise.rb b/lib/open_project/enterprise.rb
index 56273a22587..f7959ba7d08 100644
--- a/lib/open_project/enterprise.rb
+++ b/lib/open_project/enterprise.rb
@@ -46,7 +46,7 @@ module OpenProject
end
def active_user_count
- User.not_builtin.active.count
+ User.human.active.count
end
##
@@ -61,7 +61,7 @@ module OpenProject
# While the active user limit has not been reached yet it would be reached
# if all registered and invited users were to activate their accounts.
def imminent_user_limit?
- User.not_builtin.active_or_registered.count >= user_limit if user_limit
+ User.human.not_locked.count >= user_limit if user_limit
end
def fail_fast?
diff --git a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
index aeac08bfae1..93b12b716ea 100644
--- a/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
+++ b/lib/plugins/acts_as_watchable/lib/acts_as_watchable.rb
@@ -109,18 +109,15 @@ module Redmine
# because while they have the right to be added as watchers having
# them pop up in every project would be weird.
def possible_watcher_users
- # In rails 6, for reasons I did not look into, a different sql is produced
- # when issuing
- # User.active_or_registered.allowed_members(self.class.acts_as_watchable_permission, project)
- # compared to
- # User.allowed_members(self.class.acts_as_watchable_permission, project).active_or_registered
- scope = if project.public?
- User.allowed(self.class.acts_as_watchable_permission, project)
- else
- User.allowed_members(self.class.acts_as_watchable_permission, project)
- end
-
- scope.active_or_registered
+ active_scope = Principal.not_locked.user
+
+ allowed_scope = if project.public?
+ User.allowed(self.class.acts_as_watchable_permission, project)
+ else
+ User.allowed_members(self.class.acts_as_watchable_permission, project)
+ end
+
+ active_scope.where(id: allowed_scope)
end
# Returns an array of users that are proposed as watchers
diff --git a/modules/backlogs/app/views/rb_taskboards/show.html.erb b/modules/backlogs/app/views/rb_taskboards/show.html.erb
index d7417482062..b892b6eb353 100644
--- a/modules/backlogs/app/views/rb_taskboards/show.html.erb
+++ b/modules/backlogs/app/views/rb_taskboards/show.html.erb
@@ -125,7 +125,7 @@ See docs/COPYRIGHT.rdoc for more details.
<div id="helpers">
<select class="assigned_to_id template" id="assigned_to_id_options">
<option value=""> </option>
- <% @project.possible_assignees.each do |user| %>
+ <% Principal.possible_assignee(@project).each do |user| %>
<option value="<%= user.id %>" color="<%= get_backlogs_preference(user, :task_color) %>">
<%= user.name %>
</option>
diff --git a/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb b/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb
index 4e4bd3492c8..47e72ae727b 100644
--- a/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb
+++ b/modules/bim/app/representers/bim/bcf/api/v2_1/project_extensions/representer.rb
@@ -59,8 +59,7 @@ module Bim::Bcf::API::V2_1
property :user_id_type,
getter: ->(decorator:, **) {
decorator.with_check(%i[manage_bcf view_members]) do
- # TODO: Move possible_assignees handling into wp base contract
- model.project.possible_assignees.pluck(:mail)
+ assignable_assignees.pluck(:mail)
end
}
diff --git a/modules/bim/spec/representers/bcf/api/v2_1/project_extensions/representer_spec.rb b/modules/bim/spec/representers/bcf/api/v2_1/project_extensions/representer_spec.rb
index f24e564d941..46d89f78595 100644
--- a/modules/bim/spec/representers/bcf/api/v2_1/project_extensions/representer_spec.rb
+++ b/modules/bim/spec/representers/bcf/api/v2_1/project_extensions/representer_spec.rb
@@ -35,11 +35,7 @@ describe Bim::Bcf::API::V2_1::ProjectExtensions::Representer, 'rendering' do
let(:status) { FactoryBot.build_stubbed(:status) }
let(:user) { FactoryBot.build_stubbed(:user) }
let(:project) do
- FactoryBot.build_stubbed(:project).tap do |p|
- allow(p)
- .to receive(:possible_assignees)
- .and_return([user])
- end
+ FactoryBot.build_stubbed(:project)
end
let(:work_package) { FactoryBot.build_stubbed(:stubbed_work_package, project: project) }
let(:priority) { FactoryBot.build_stubbed(:priority) }
@@ -50,7 +46,8 @@ describe Bim::Bcf::API::V2_1::ProjectExtensions::Representer, 'rendering' do
model: work_package,
assignable_types: [type_task],
assignable_priorities: [priority],
- assignable_statuses: [status])
+ assignable_statuses: [status],
+ assignable_assignees: [user])
end
let(:instance) { described_class.new(contract) }
let(:subject) { instance.to_json }
diff --git a/modules/budgets/app/models/budget.rb b/modules/budgets/app/models/budget.rb
index 2463920f5eb..c6fbed22d8f 100644
--- a/modules/budgets/app/models/budget.rb
+++ b/modules/budgets/app/models/budget.rb
@@ -268,7 +268,7 @@ class Budget < ApplicationRecord
attributes &&
attributes[:hours].to_f.positive? &&
attributes[:user_id].to_i.positive? &&
- project.possible_assignees.map(&:id).include?(attributes[:user_id].to_i)
+ Principal.possible_assignee(project).where(id: attributes[:user_id].to_i).exists?
end
def valid_material_budget_attributes?(attributes)
diff --git a/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb b/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb
index 8d4bbaeefee..68df94b24e2 100644
--- a/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb
+++ b/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb
@@ -68,7 +68,7 @@ See docs/COPYRIGHT.rdoc for more details.
<td class="user">
<label class="hidden-for-sighted" for="<%= id_prefix %>_user_id"><%= t(:label_user) %></label>
<%= cost_form.select :user_id,
- @project.possible_assignees.sort.map { |u| [u.name, u.id] },
+ Principal.possible_assignee(@project).sort.map { |u| [u.name, u.id] },
{ prompt: true },
{
index: id_or_index,
diff --git a/modules/costs/app/helpers/costlog_helper.rb b/modules/costs/app/helpers/costlog_helper.rb
index b3e2239ac5d..42e50e83386 100644
--- a/modules/costs/app/helpers/costlog_helper.rb
+++ b/modules/costs/app/helpers/costlog_helper.rb
@@ -38,8 +38,9 @@ module CostlogHelper
end
def user_collection_for_select_options(_options = {})
- users = @project.possible_assignees
- users.map { |t| [t.name, t.id] }
+ Principal
+ .possible_assignee(@project)
+ .map { |t| [t.name, t.id] }
end
def extended_progress_bar(pcts, options = {})
diff --git a/modules/dashboards/spec/features/members_spec.rb b/modules/dashboards/spec/features/members_spec.rb
index 5ab3a510901..aa16d76a8b5 100644
--- a/modules/dashboards/spec/features/members_spec.rb
+++ b/modules/dashboards/spec/features/members_spec.rb
@@ -43,6 +43,12 @@ describe 'Members widget on dashboard', type: :feature, js: true do
let!(:no_view_member_user) do
FactoryBot.create :user, lastname: "No_View", member_in_project: project, member_through_role: no_view_member_role
end
+ let!(:placeholder_user) do
+ FactoryBot.create :placeholder_user,
+ lastname: "Placeholder user",
+ member_in_project: project,
+ member_through_role: no_view_member_role
+ end
let!(:invisible_user) do
FactoryBot.create :user, lastname: "Invisible", member_in_project: other_project, member_through_role: role
end
@@ -89,6 +95,8 @@ describe 'Members widget on dashboard', type: :feature, js: true do
.to have_content no_view_member_role
expect(page)
.to have_content no_view_member_user.name
+ expect(page)
+ .to have_content placeholder_user.name
end
end
diff --git a/modules/reporting/app/models/cost_query/filter/user_id.rb b/modules/reporting/app/models/cost_query/filter/user_id.rb
index 06dc9bfded3..2049e1529b9 100644
--- a/modules/reporting/app/models/cost_query/filter/user_id.rb
+++ b/modules/reporting/app/models/cost_query/filter/user_id.rb
@@ -57,7 +57,7 @@ class CostQuery::Filter::UserId < Report::Filter::Base
# Excludes the anonymous user
users = User.joins(members: :project)
.merge(Project.visible)
- .not_builtin
+ .human
.select(User::USER_FORMATS_STRUCTURE[Setting.user_format].map(&:to_s) << :id)
.distinct
diff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rb
index af8b6fbd516..3bc8d626067 100644
--- a/spec/contracts/work_packages/base_contract_spec.rb
+++ b/spec/contracts/work_packages/base_contract_spec.rb
@@ -55,6 +55,15 @@ describe WorkPackages::BaseContract do
end
let(:project) { FactoryBot.build_stubbed(:project) }
let(:current_user) { member }
+ let!(:assignable_assignees_scope) do
+ scope = double 'assignable assignees scope'
+
+ allow(Principal)
+ .to receive(:possible_assignee)
+ .and_return scope
+
+ scope
+ end
let(:permissions) do
%i(
view_work_packages
diff --git a/spec/contracts/work_packages/create_contract_spec.rb b/spec/contracts/work_packages/create_contract_spec.rb
index d75dbc9d6fe..26d680aaeef 100644
--- a/spec/contracts/work_packages/create_contract_spec.rb
+++ b/spec/contracts/work_packages/create_contract_spec.rb
@@ -31,7 +31,8 @@ require 'spec_helper'
require 'contracts/work_packages/shared_base_contract'
describe WorkPackages::CreateContract do
- let(:work_package) { WorkPackage.new }
+ let(:work_package) { WorkPackage.new project: work_package_project }
+ let(:work_package_project) { project }
let(:project) { FactoryBot.build_stubbed(:project) }
let(:user) { FactoryBot.build_stubbed(:user) }
diff --git a/spec/contracts/work_packages/shared_base_contract.rb b/spec/contracts/work_packages/shared_base_contract.rb
index a62ef2901ca..07e61232cc2 100644
--- a/spec/contracts/work_packages/shared_base_contract.rb
+++ b/spec/contracts/work_packages/shared_base_contract.rb
@@ -29,7 +29,6 @@
#++
shared_examples_for 'work package contract' do
- let(:project) { FactoryBot.build_stubbed(:project) }
let(:user) { FactoryBot.build_stubbed(:user) }
let(:other_user) { FactoryBot.build_stubbed(:user) }
let(:policy) { double(WorkPackagePolicy, allowed?: true) }
@@ -48,6 +47,23 @@ shared_examples_for 'work package contract' do
.and_return(policy)
end
+ let(:possible_assignees) { [] }
+ let!(:assignable_assignees_scope) do
+ scope = double 'assignable assignees scope'
+
+ allow(Principal)
+ .to receive(:possible_assignee)
+ .with(work_package_project)
+ .and_return scope
+
+ allow(scope)
+ .to receive(:exists?) do |hash|
+ possible_assignees.map(&:id).include?(hash[:id])
+ end
+
+ scope
+ end
+
shared_examples_for 'has no error on' do |property|
it property do
expect(validated_contract.errors[property]).to be_empty
@@ -55,37 +71,17 @@ shared_examples_for 'work package contract' do
end
describe 'assigned_to_id' do
- let(:assignee_members) { double('assignee_members') }
-
before do
- allow(work_package)
- .to receive(:project)
- .and_return(project)
-
- allow(project)
- .to receive(:possible_assignee_members)
- .and_return(assignee_members)
-
- allow(assignee_members)
- .to receive(:exists?)
- .with(user_id: other_user.id)
- .and_return true
-
- work_package.assigned_to = other_user
+ work_package.assigned_to_id = other_user.id
end
context 'if the assigned user is a possible assignee' do
+ let(:possible_assignees) { [other_user] }
+
it_behaves_like 'has no error on', :assigned_to
end
context 'if the assigned user is not a possible assignee' do
- before do
- allow(assignee_members)
- .to receive(:exists?)
- .with(user_id: other_user.id)
- .and_return false
- end
-
it 'is not a valid assignee' do
error = I18n.t('api_v3.errors.validation.invalid_user_assigned_to_work_package',
property: I18n.t('attributes.assignee'))
@@ -94,48 +90,23 @@ shared_examples_for 'work package contract' do
end
context 'if the project is not set' do
- before do
- allow(work_package)
- .to receive(:project)
- .and_return(nil)
- end
+ let(:work_package_project) { nil }
it_behaves_like 'has no error on', :assigned_to
end
end
describe 'responsible_id' do
- let(:responsible_members) { double('responsible_members') }
-
before do
- allow(work_package)
- .to receive(:project)
- .and_return(project)
-
- allow(project)
- .to receive(:possible_responsible_members)
- .and_return(responsible_members)
-
- allow(responsible_members)
- .to receive(:exists?)
- .with(user_id: other_user.id)
- .and_return true
-
- work_package.responsible = other_user
+ work_package.responsible_id = other_user.id
end
context 'if the responsible user is a possible responsible' do
+ let(:possible_assignees) { [other_user] }
it_behaves_like 'has no error on', :responsible
end
context 'if the assigned user is not a possible responsible' do
- before do
- allow(responsible_members)
- .to receive(:exists?)
- .with(user_id: other_user.id)
- .and_return false
- end
-
it 'is not a valid responsible' do
error = I18n.t('api_v3.errors.validation.invalid_user_assigned_to_work_package',
property: I18n.t('attributes.responsible'))
@@ -144,13 +115,23 @@ shared_examples_for 'work package contract' do
end
context 'if the project is not set' do
- before do
- allow(work_package)
- .to receive(:project)
- .and_return(nil)
- end
+ let(:work_package_project) { nil }
it_behaves_like 'has no error on', :responsible
end
end
+
+ describe '#assignable_assignees' do
+ it 'returns the Principal`s possible_assignee scope' do
+ expect(subject.assignable_assignees)
+ .to eql assignable_assignees_scope
+ end
+ end
+
+ describe '#assignable_responsibles' do
+ it 'returns the Principal`s possible_assignee scope' do
+ expect(subject.assignable_responsibles)
+ .to eql assignable_assignees_scope
+ end
+ end
end
diff --git a/spec/contracts/work_packages/update_contract_spec.rb b/spec/contracts/work_packages/update_contract_spec.rb
index b90dd66ef4b..928336aa368 100644
--- a/spec/contracts/work_packages/update_contract_spec.rb
+++ b/spec/contracts/work_packages/update_contract_spec.rb
@@ -31,7 +31,7 @@ require 'spec_helper'
require 'contracts/work_packages/shared_base_contract'
describe WorkPackages::UpdateContract do
- let(:project) do
+ let(:work_package_project) do
FactoryBot.build_stubbed(:project, public: false).tap do |p|
allow(Project)
.to receive(:find)
@@ -41,7 +41,7 @@ describe WorkPackages::UpdateContract do
end
let(:work_package) do
FactoryBot.build_stubbed(:work_package,
- project: project,
+ project: work_package_project,
type: type).tap do |wp|
wp_scope = double('wp scope')
@@ -63,14 +63,17 @@ describe WorkPackages::UpdateContract do
before do
allow(user)
.to receive(:allowed_to?) do |permission, context|
- permissions.include?(permission) && context == project
+ permissions.include?(permission) && context == work_package_project
end
end
subject(:contract) { described_class.new(work_package, user) }
it_behaves_like 'work package contract' do
- let(:work_package) { FactoryBot.build_stubbed(:work_package) }
+ let(:work_package) do
+ FactoryBot.build_stubbed(:work_package,
+ project: work_package_project)
+ end
end
describe 'lock_version' do
@@ -162,7 +165,7 @@ describe WorkPackages::UpdateContract do
before do
allow(user)
.to receive(:allowed_to?) do |permission, context|
- permissions.include?(permission) && context == project ||
+ permissions.include?(permission) && context == work_package_project ||
target_permissions.include?(permission) && context == target_project
end
@@ -171,7 +174,7 @@ describe WorkPackages::UpdateContract do
if work_package.project_id == target_project.id
target_project
else
- project
+ work_package_project
end
end
diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb
index ed112567b70..b143c7394b0 100644
--- a/spec/controllers/account_controller_spec.rb
+++ b/spec/controllers/account_controller_spec.rb
@@ -642,7 +642,7 @@ describe AccountController, type: :controller do
it 'set the user status to active' do
user = User.where(login: 'register').last
expect(user).not_to be_nil
- expect(user.status).to eq(User::STATUSES[:active])
+ expect(user).to be_active
end
it 'calls the user_registered callback' do
@@ -955,13 +955,13 @@ describe AccountController, type: :controller do
end
context 'registered user' do
- let(:status) { User::STATUSES[:registered] }
+ let(:status) { User.statuses[:registered] }
it_behaves_like "activation is blocked due to user limit"
end
context 'invited user' do
- let(:status) { User::STATUSES[:invited] }
+ let(:status) { User.statuses[:invited] }
it_behaves_like "activation is blocked due to user limit"
end
diff --git a/spec/controllers/concerns/auth_source_sso_spec.rb b/spec/controllers/concerns/auth_source_sso_spec.rb
index 1b6d2f3f486..3fd311a7d7e 100644
--- a/spec/controllers/concerns/auth_source_sso_spec.rb
+++ b/spec/controllers/concerns/auth_source_sso_spec.rb
@@ -111,7 +111,7 @@ describe MyController, type: :controller do
context 'when the user is invited' do
let!(:user) {
- FactoryBot.create :user, login: login, status: Principal::STATUSES[:invited], auth_source_id: auth_source.id
+ FactoryBot.create :user, login: login, status: Principal.statuses[:invited], auth_source_id: auth_source.id
}
it "should log in given user and activate it" do
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb
index 460492b3437..716626821f5 100644
--- a/spec/controllers/users_controller_spec.rb
+++ b/spec/controllers/users_controller_spec.rb
@@ -333,7 +333,7 @@ describe UsersController, type: :controller do
describe '#change_status_info' do
let!(:registered_user) do
- FactoryBot.create(:user, status: User::STATUSES[:registered])
+ FactoryBot.create(:user, status: User.statuses[:registered])
end
before do
@@ -386,7 +386,7 @@ describe UsersController, type: :controller do
} do
describe 'WHEN activating a registered user' do
let!(:registered_user) do
- FactoryBot.create(:user, status: User::STATUSES[:registered],
+ FactoryBot.create(:user, status: User.statuses[:registered],
language: 'de')
end
@@ -399,7 +399,7 @@ describe UsersController, type: :controller do
post :change_status,
params: {
id: registered_user.id,
- user: { status: User::STATUSES[:active] },
+ user: { status: User.statuses[:active] },
activate: '1'
}
end
diff --git a/spec/factories/user_factory.rb b/spec/factories/user_factory.rb
index cde7d3819d5..5bf3bfff7e0 100644
--- a/spec/factories/user_factory.rb
+++ b/spec/factories/user_factory.rb
@@ -38,7 +38,7 @@ FactoryBot.define do
mail_notification { OpenProject::VERSION::MAJOR > 0 ? 'all' : true }
language { 'en' }
- status { User::STATUSES[:active] }
+ status { User.statuses[:active] }
admin { false }
first_login { false if User.table_exists? and User.columns.map(&:name).include? 'first_login' }
@@ -60,11 +60,11 @@ FactoryBot.define do
sequence(:mail) do |n| "bob#{n}[email protected]" end
password { 'adminADMIN!' }
password_confirmation { 'adminADMIN!' }
- status { User::STATUSES[:locked] }
+ status { User.statuses[:locked] }
end
factory :invited_user do
- status { User::STATUSES[:invited] }
+ status { User.statuses[:invited] }
end
end
diff --git a/spec/features/custom_fields/multi_user_custom_field_spec.rb b/spec/features/custom_fields/multi_user_custom_field_spec.rb
index 29139d705a2..d1a1d88b988 100644
--- a/spec/features/custom_fields/multi_user_custom_field_spec.rb
+++ b/spec/features/custom_fields/multi_user_custom_field_spec.rb
@@ -26,7 +26,7 @@ describe "multi select custom values", js: true do
# We include an invited member to check at the same time that invited users are properly
# offered for user custom fields as they weren't before.
let(:member_statuses) do
- [User::STATUSES[:active], User::STATUSES[:active], User::STATUSES[:invited]]
+ [User.statuses[:active], User.statuses[:active], User.statuses[:invited]]
end
let(:members) do
diff --git a/spec/features/members/membership_filter_spec.rb b/spec/features/members/membership_filter_spec.rb
index ef4c4fd402f..c267a85afe6 100644
--- a/spec/features/members/membership_filter_spec.rb
+++ b/spec/features/members/membership_filter_spec.rb
@@ -34,21 +34,21 @@ feature 'group memberships through groups page', type: :feature, js: true do
let!(:peter) do
FactoryBot.create :user,
- firstname: 'Peter',
- lastname: 'Pan',
- member_in_project: project,
- member_through_role: role
+ firstname: 'Peter',
+ lastname: 'Pan',
+ member_in_project: project,
+ member_through_role: role
end
let!(:hannibal) do
FactoryBot.create :user,
- firstname: 'Pan',
- lastname: 'Hannibal',
- member_in_project: project,
- member_through_role: role
+ firstname: 'Pan',
+ lastname: 'Hannibal',
+ member_in_project: project,
+ member_through_role: role
end
let(:role) { FactoryBot.create(:role, permissions: %i(add_work_packages)) }
diff --git a/spec/features/members/membership_spec.rb b/spec/features/members/membership_spec.rb
index 4b8a3a872ce..76104117557 100644
--- a/spec/features/members/membership_spec.rb
+++ b/spec/features/members/membership_spec.rb
@@ -28,97 +28,54 @@
require 'spec_helper'
-feature 'group memberships through groups page', type: :feature, js: true do
+feature 'Administrating memberships via the project settings', type: :feature, js: true do
using_shared_fixtures :admin
- let!(:project) { FactoryBot.create :project, name: 'Project 1', identifier: 'project1' }
+ let(:current_user) do
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_through_role: manager)
+ end
+ let!(:project) { FactoryBot.create :project }
let!(:peter) { FactoryBot.create :user, firstname: 'Peter', lastname: 'Pan', mail: '[email protected]' }
let!(:hannibal) { FactoryBot.create :user, firstname: 'Hannibal', lastname: 'Smith', mail: '[email protected]' }
- let!(:crash) { FactoryBot.create :user, firstname: "<script>alert('h4x');</script>",
- lastname: "<script>alert('h4x');</script>" }
-
- let(:group) { FactoryBot.create :group, lastname: 'A-Team' }
-
- let!(:manager) { FactoryBot.create :role, name: 'Manager' }
- let!(:developer) { FactoryBot.create :role, name: 'Developer' }
-
- let(:members_page) { Pages::Members.new project.identifier }
-
- before do
- allow(User).to receive(:current).and_return admin
-
- group.add_members! peter
- group.add_members! hannibal
+ let!(:developer_placeholder) { FactoryBot.create :placeholder_user, name: 'Developer 1' }
+ let!(:crash) do
+ FactoryBot.create :user,
+ firstname: "<script>alert('h4x');</script>",
+ lastname: "<script>alert('h4x');</script>"
end
-
- shared_examples 'adding and removing principals' do
- scenario 'Adding and Removing a Group as Member' do
- members_page.visit!
- SeleniumHubWaiter.wait
- members_page.add_user! 'A-Team', as: 'Manager'
-
- expect(members_page).to have_added_group('A-Team')
-
- SeleniumHubWaiter.wait
- members_page.remove_group! 'A-Team'
- expect(page).to have_text 'Removed A-Team from project'
- expect(page).to have_text 'There are currently no members part of this project.'
- end
-
- scenario 'Adding and removing a User as Member' do
- members_page.visit!
- SeleniumHubWaiter.wait
- members_page.add_user! 'Hannibal Smith', as: 'Manager'
-
- expect(members_page).to have_added_user 'Hannibal Smith'
-
- SeleniumHubWaiter.wait
- members_page.remove_user! 'Hannibal Smith'
- expect(page).to have_text 'Removed Hannibal Smith from project'
- expect(page).to have_text 'There are currently no members part of this project.'
+ let!(:group) do
+ FactoryBot.create(:group, lastname: 'A-Team').tap do |group|
+ User.execute_as User.admin.first do
+ group.add_members! peter
+ group.add_members! hannibal
+ end
end
+ end
- scenario 'Entering a Username as Member in firstname, lastname order' do
- members_page.visit!
- SeleniumHubWaiter.wait
- members_page.open_new_member!
+ let!(:manager) { FactoryBot.create :role, name: 'Manager', permissions: [:manage_members] }
+ let!(:developer) { FactoryBot.create :role, name: 'Developer' }
+ let(:member1) { FactoryBot.create(:member, principal: peter, project: project, roles: [manager]) }
+ let(:member2) { FactoryBot.create(:member, principal: hannibal, project: project, roles: [developer]) }
+ let(:member3) { FactoryBot.create(:member, principal: group, project: project, roles: [manager]) }
- SeleniumHubWaiter.wait
- members_page.search_principal! 'Hannibal S'
- expect(members_page).to have_search_result 'Hannibal Smith'
- end
+ let!(:existing_members) { [] }
- scenario 'Entering a Username as Member in lastname, firstname order' do
- members_page.visit!
- SeleniumHubWaiter.wait
- members_page.open_new_member!
+ let(:members_page) { Pages::Members.new project.identifier }
- SeleniumHubWaiter.wait
- members_page.search_principal! 'Smith, H'
- expect(members_page).to have_search_result 'Hannibal Smith'
- end
+ before do
+ login_as(admin)
- scenario 'Escaping should work properly when entering a name' do
- members_page.visit!
- SeleniumHubWaiter.wait
- members_page.open_new_member!
- SeleniumHubWaiter.wait
- members_page.search_principal! 'script'
+ members_page.visit!
- expect(members_page).not_to have_alert_dialog
- expect(members_page).to have_search_result "<script>alert('h4x');</script>"
- end
+ SeleniumHubWaiter.wait
end
context 'with members in the project' do
- let!(:member1) { FactoryBot.create(:member, principal: peter, project: project, roles: [manager]) }
- let!(:member2) { FactoryBot.create(:member, principal: hannibal, project: project, roles: [developer]) }
- let!(:member3) { FactoryBot.create(:member, principal: group, project: project, roles: [manager]) }
+ let!(:existing_members) { [member1, member2, member3] }
scenario 'sorting the page' do
- members_page.visit!
-
- SeleniumHubWaiter.wait
members_page.sort_by 'last name'
members_page.expect_sorted_by 'last name'
@@ -146,16 +103,62 @@ feature 'group memberships through groups page', type: :feature, js: true do
end
end
- context 'with a user' do
- it_behaves_like 'adding and removing principals'
+ scenario 'Adding and Removing a Group as Member' do
+ members_page.add_user! 'A-Team', as: 'Manager'
- scenario 'Escaping should work properly when selecting a user' do
- members_page.visit!
- members_page.open_new_member!
- members_page.select_principal! 'script'
+ expect(members_page).to have_added_group('A-Team')
+ SeleniumHubWaiter.wait
- expect(members_page).not_to have_alert_dialog
- expect(page).to have_text "<script>alert('h4x');</script>"
- end
+ members_page.remove_group! 'A-Team'
+ expect(page).to have_text 'Removed A-Team from project'
+ expect(page).to have_text 'There are currently no members part of this project.'
+ end
+
+ scenario 'Adding and removing a User as Member' do
+ members_page.add_user! 'Hannibal Smith', as: 'Manager'
+
+ expect(members_page).to have_added_user 'Hannibal Smith'
+
+ SeleniumHubWaiter.wait
+ members_page.remove_user! 'Hannibal Smith'
+ expect(page).to have_text 'Removed Hannibal Smith from project'
+ expect(page).to have_text 'There are currently no members part of this project.'
+ end
+
+ scenario 'Adding and removing a Placeholder as Member' do
+ members_page.add_user! developer_placeholder.name, as: developer.name
+
+ expect(members_page).to have_added_user developer_placeholder.name
+
+ SeleniumHubWaiter.wait
+ members_page.remove_user! developer_placeholder.name
+ expect(page).to have_text "Removed #{developer_placeholder.name} from project"
+ expect(page).to have_text 'There are currently no members part of this project.'
+ end
+
+ scenario 'Entering a Username as Member in firstname, lastname order' do
+ members_page.open_new_member!
+ SeleniumHubWaiter.wait
+
+ members_page.search_principal! 'Hannibal S'
+ expect(members_page).to have_search_result 'Hannibal Smith'
+ end
+
+ scenario 'Entering a Username as Member in lastname, firstname order' do
+ members_page.open_new_member!
+ SeleniumHubWaiter.wait
+
+ members_page.search_principal! 'Smith, H'
+ expect(members_page).to have_search_result 'Hannibal Smith'
+ end
+
+ scenario 'Escaping should work properly when entering a name' do
+ members_page.open_new_member!
+ SeleniumHubWaiter.wait
+
+ members_page.search_principal! 'script'
+
+ expect(members_page).not_to have_alert_dialog
+ expect(members_page).to have_search_result "<script>alert('h4x');</script>"
end
end
diff --git a/spec/features/users/index_spec.rb b/spec/features/users/index_spec.rb
index 26e92a4cd0a..01241e4d993 100644
--- a/spec/features/users/index_spec.rb
+++ b/spec/features/users/index_spec.rb
@@ -32,8 +32,8 @@ describe 'index users', type: :feature do
let!(:current_user) { FactoryBot.create :admin, created_at: 1.hour.ago }
let!(:anonymous) { FactoryBot.create :anonymous }
let!(:active_user) { FactoryBot.create :user, created_at: 1.minute.ago }
- let!(:registered_user) { FactoryBot.create :user, status: User::STATUSES[:registered] }
- let!(:invited_user) { FactoryBot.create :user, status: User::STATUSES[:invited] }
+ let!(:registered_user) { FactoryBot.create :user, status: User.statuses[:registered] }
+ let!(:invited_user) { FactoryBot.create :user, status: User.statuses[:invited] }
let(:index_page) { Pages::Admin::Users::Index.new }
before do
diff --git a/spec/features/users/self_registration_spec.rb b/spec/features/users/self_registration_spec.rb
index b06fce3573c..fd5b5247256 100644
--- a/spec/features/users/self_registration_spec.rb
+++ b/spec/features/users/self_registration_spec.rb
@@ -96,7 +96,7 @@ describe 'user self registration', type: :feature, js: true do
expect(page)
.to have_content('Your account was created and is now pending administrator approval.')
- registered_user = User.find_by(status: Principal::STATUSES[:registered])
+ registered_user = User.find_by(status: Principal.statuses[:registered])
# Trying unsuccessfully to login
login_with 'heidi', 'test123=321test'
diff --git a/spec/features/work_packages/edit_work_package_spec.rb b/spec/features/work_packages/edit_work_package_spec.rb
index 5a0a487dd81..f08295e45f4 100644
--- a/spec/features/work_packages/edit_work_package_spec.rb
+++ b/spec/features/work_packages/edit_work_package_spec.rb
@@ -26,6 +26,11 @@ describe 'edit work package', js: true do
member_in_project: project,
member_through_role: manager_role
end
+ let(:placeholder_user) do
+ FactoryBot.create :placeholder_user,
+ member_in_project: project,
+ member_through_role: manager_role
+ end
let(:cf_all) do
FactoryBot.create :work_package_custom_field, is_for_all: true, field_format: 'text'
@@ -176,6 +181,17 @@ describe 'edit work package', js: true do
expect(work_package.assigned_to).to be_nil
end
+ it 'allows selecting placeholder users for assignee and responsible' do
+ wp_page.update_attributes assignee: placeholder_user.name,
+ responsible: placeholder_user.name
+
+ wp_page.expect_attributes assignee: placeholder_user.name,
+ responsible: placeholder_user.name
+
+ wp_page.expect_activity_message("Assignee set to #{placeholder_user.name}")
+ wp_page.expect_activity_message("Accountable set to #{placeholder_user.name}")
+ end
+
context 'switching to custom field with required CF' do
let(:custom_field) do
FactoryBot.create(
diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb
index 94a57feb2b7..4329daa0aef 100644
--- a/spec/helpers/users_helper_spec.rb
+++ b/spec/helpers/users_helper_spec.rb
@@ -32,11 +32,13 @@ describe UsersHelper, type: :helper do
include UsersHelper
def build_user(status, blocked)
- user = FactoryBot.build(:user)
- allow(user).to receive(:status).and_return(User::STATUSES[status])
- allow(user).to receive(:failed_too_many_recent_login_attempts?).and_return(blocked)
- allow(user).to receive(:failed_login_count).and_return(3)
- user
+ FactoryBot.build_stubbed(:user,
+ status: status,
+ failed_login_count: 3).tap do |user|
+ allow(user)
+ .to receive(:failed_too_many_recent_login_attempts?)
+ .and_return(blocked)
+ end
end
describe 'full_user_status' do
diff --git a/spec/lib/api/v3/groups/group_representer_spec.rb b/spec/lib/api/v3/groups/group_representer_spec.rb
index 2fa577cce9a..f3333fdc8d8 100644
--- a/spec/lib/api/v3/groups/group_representer_spec.rb
+++ b/spec/lib/api/v3/groups/group_representer_spec.rb
@@ -102,37 +102,26 @@ describe ::API::V3::Groups::GroupRepresenter do
representer.to_json
end
- describe 'caching' do
- it 'is based on the representer\'s cache_key' do
- expect(OpenProject::Cache)
- .to receive(:fetch)
- .with(representer.json_cache_key)
- .and_call_original
-
- representer.to_json
- end
+ describe '#json_cache_key' do
+ let!(:former_cache_key) { representer.json_cache_key }
- describe '#json_cache_key' do
- let!(:former_cache_key) { representer.json_cache_key }
+ it 'includes the name of the representer class' do
+ expect(representer.json_cache_key)
+ .to include('API', 'V3', 'Groups', 'GroupRepresenter')
+ end
- it 'includes the name of the representer class' do
+ it 'changes when the locale changes' do
+ I18n.with_locale(:fr) do
expect(representer.json_cache_key)
- .to include('API', 'V3', 'Groups', 'GroupRepresenter')
- end
-
- it 'changes when the locale changes' do
- I18n.with_locale(:fr) do
- expect(representer.json_cache_key)
- .not_to eql former_cache_key
- end
+ .not_to eql former_cache_key
end
+ end
- it 'changes when the group is updated' do
- group.updated_at = Time.now + 20.seconds
+ it 'changes when the group is updated' do
+ group.updated_at = Time.now + 20.seconds
- expect(representer.json_cache_key)
- .not_to eql former_cache_key
- end
+ expect(representer.json_cache_key)
+ .not_to eql former_cache_key
end
end
end
diff --git a/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb b/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb
index 6e99e6ab661..80e2d3a3b6b 100644
--- a/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb
+++ b/spec/lib/api/v3/memberships/schemas/membership_schema_representer_spec.rb
@@ -197,7 +197,7 @@ describe ::API::V3::Memberships::Schemas::MembershipSchemaRepresenter do
context 'if having no project' do
it_behaves_like 'links to allowed values via collection link' do
let(:href) do
- statuses = [Principal::STATUSES[:locked].to_s]
+ statuses = [Principal.statuses[:locked].to_s]
filters = [{ 'status' => { 'operator' => '!', 'values' => statuses } }]
api_v3_paths.path_for(:principals, filters: filters)
@@ -210,7 +210,7 @@ describe ::API::V3::Memberships::Schemas::MembershipSchemaRepresenter do
it_behaves_like 'links to allowed values via collection link' do
let(:href) do
- statuses = [Principal::STATUSES[:locked].to_s]
+ statuses = [Principal.statuses[:locked].to_s]
status_filter = { 'status' => { 'operator' => '!', 'values' => statuses } }
member_filter = { 'member' => { 'operator' => '!', 'values' => [assigned_project.id.to_s] } }
diff --git a/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb b/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
new file mode 100644
index 00000000000..dff089a752f
--- /dev/null
+++ b/spec/lib/api/v3/placeholder_users/placeholder_user_representer_rendering_spec.rb
@@ -0,0 +1,173 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe ::API::V3::PlaceholderUsers::PlaceholderUserRepresenter, 'rendering' do
+ include ::API::V3::Utilities::PathHelper
+
+ let(:placeholder_user) { FactoryBot.build_stubbed(:placeholder_user) }
+ let(:current_user) { FactoryBot.build_stubbed(:user) }
+ let(:representer) { described_class.new(placeholder_user, current_user: current_user) }
+ let(:memberships_path) do
+ filters = [
+ {
+ principal: {
+ operator: '=',
+ values: [placeholder_user.id.to_s]
+ }
+ }
+ ]
+
+ api_v3_paths.path_for(:memberships, filters: filters)
+ end
+ let(:global_permissions) { [] }
+
+ subject(:generated) { representer.to_json }
+
+ before do
+ allow(current_user)
+ .to receive(:allowed_to_globally?) do |requested_permission|
+ global_permissions.include?(requested_permission)
+ end
+ end
+
+ describe '_links' do
+ context 'self' do
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'self' }
+ let(:href) { api_v3_paths.placeholder_user placeholder_user.id }
+ let(:title) { placeholder_user.name }
+ end
+ end
+
+ context 'memberships' do
+ it_behaves_like 'has no link' do
+ let(:link) { 'memberships' }
+ end
+
+ context 'user allowed to see members' do
+ let(:global_permissions) { [:view_members] }
+
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'memberships' }
+ let(:href) { memberships_path }
+ let(:title) { I18n.t(:label_member_plural) }
+ end
+ end
+
+ context 'user allowed to manage members' do
+ let(:global_permissions) { [:manage_members] }
+
+ it_behaves_like 'has a titled link' do
+ let(:link) { 'memberships' }
+ let(:href) { memberships_path }
+ let(:title) { I18n.t(:label_member_plural) }
+ end
+ end
+ end
+ end
+
+ describe 'properties' do
+ it_behaves_like 'property', :_type do
+ let(:value) { 'PlaceholderUser' }
+ end
+
+ context 'as regular user' do
+ it_behaves_like 'property', :id do
+ let(:value) { placeholder_user.id }
+ end
+
+ it_behaves_like 'property', :name do
+ let(:value) { placeholder_user.name }
+ end
+
+ it 'hides the updatedAt property' do
+ is_expected.not_to have_json_path('updatedAt')
+ end
+
+ it 'hides the createdAt property' do
+ is_expected.not_to have_json_path('createdAt')
+ end
+ end
+
+ context 'as admin' do
+ let(:current_user) { FactoryBot.build_stubbed(:admin) }
+
+ it_behaves_like 'property', :id do
+ let(:value) { placeholder_user.id }
+ end
+
+ it_behaves_like 'property', :name do
+ let(:value) { placeholder_user.name }
+ end
+
+ it_behaves_like 'datetime property', :createdAt do
+ let(:value) { placeholder_user.created_at }
+ end
+
+ it_behaves_like 'datetime property', :updatedAt do
+ let(:value) { placeholder_user.updated_at }
+ end
+ end
+ end
+
+ describe 'caching' do
+ it 'is based on the representer\'s cache_key' do
+ expect(OpenProject::Cache)
+ .to receive(:fetch)
+ .with(representer.json_cache_key)
+ .and_call_original
+
+ representer.to_json
+ end
+
+ describe '#json_cache_key' do
+ let!(:former_cache_key) { representer.json_cache_key }
+
+ it 'includes the name of the representer class' do
+ expect(representer.json_cache_key)
+ .to include('API', 'V3', 'PlaceholderUsers', 'PlaceholderUserRepresenter')
+ end
+
+ it 'changes when the locale changes' do
+ I18n.with_locale(:fr) do
+ expect(representer.json_cache_key)
+ .not_to eql former_cache_key
+ end
+ end
+
+ it 'changes when the placeholder is updated' do
+ placeholder_user.updated_at = Time.now + 20.seconds
+
+ expect(representer.json_cache_key)
+ .not_to eql former_cache_key
+ end
+ end
+ end
+end
diff --git a/spec/lib/api/v3/queries/query_representer_generation_spec.rb b/spec/lib/api/v3/queries/query_representer_generation_spec.rb
index 8ff0a7401bf..98c1c5a9221 100644
--- a/spec/lib/api/v3/queries/query_representer_generation_spec.rb
+++ b/spec/lib/api/v3/queries/query_representer_generation_spec.rb
@@ -34,7 +34,7 @@ describe ::API::V3::Queries::QueryRepresenter do
let(:query) { FactoryBot.build_stubbed(:query, project: project) }
let(:unpersisted_query) { FactoryBot.build(:query, project: project, user: other_user) }
let(:project) { FactoryBot.build_stubbed(:project) }
- let(:user) { double('current_user', allowed_to?: true, admin: true, admin?: true, active?: true) }
+ let(:user) { double('current_user', allowed_to_globally?: true, allowed_to?: true, admin: true, admin?: true, active?: true) }
let(:other_user) { FactoryBot.build_stubbed(:user) }
let(:embed_links) { true }
let(:representer) do
diff --git a/spec/lib/api/v3/users/user_representer_spec.rb b/spec/lib/api/v3/users/user_representer_spec.rb
index 7b09205fff2..ef37ce10868 100644
--- a/spec/lib/api/v3/users/user_representer_spec.rb
+++ b/spec/lib/api/v3/users/user_representer_spec.rb
@@ -29,7 +29,7 @@
require 'spec_helper'
describe ::API::V3::Users::UserRepresenter do
- let(:status) { Principal::STATUSES[:active] }
+ let(:status) { Principal.statuses[:active] }
let(:user) { FactoryBot.build_stubbed(:user, status: status) }
let(:current_user) { FactoryBot.build_stubbed(:user) }
let(:representer) { described_class.new(user, current_user: current_user) }
@@ -161,7 +161,7 @@ describe ::API::V3::Users::UserRepresenter do
end
context 'with a locked user' do
- let(:status) { Principal::STATUSES[:locked] }
+ let(:status) { Principal.statuses[:locked] }
it_behaves_like 'has no link' do
let(:link) { 'showUser' }
@@ -232,8 +232,8 @@ describe ::API::V3::Users::UserRepresenter do
describe 'memberships' do
before do
allow(current_user)
- .to receive(:allowed_to?) do |action, _project, options|
- permissions.include?(action) && options[:global]
+ .to receive(:allowed_to_globally?) do |action|
+ permissions.include?(action)
end
end
diff --git a/spec/lib/api/v3/utilities/custom_field_injector_spec.rb b/spec/lib/api/v3/utilities/custom_field_injector_spec.rb
index aefca719660..cf57088bed1 100644
--- a/spec/lib/api/v3/utilities/custom_field_injector_spec.rb
+++ b/spec/lib/api/v3/utilities/custom_field_injector_spec.rb
@@ -223,7 +223,7 @@ describe ::API::V3::Utilities::CustomFieldInjector do
let(:path) { cf_path }
let(:href) do
params = [{ status: { operator: '!',
- values: [Principal::STATUSES[:locked].to_s] } },
+ values: [Principal.statuses[:locked].to_s] } },
{ type: { operator: '=', values: ['User'] } },
{ member: { operator: '=', values: [schema.project_id.to_s] } }]
diff --git a/spec/lib/api/v3/utilities/path_helper_spec.rb b/spec/lib/api/v3/utilities/path_helper_spec.rb
index d2167ef6d40..b1d5cc9b88d 100644
--- a/spec/lib/api/v3/utilities/path_helper_spec.rb
+++ b/spec/lib/api/v3/utilities/path_helper_spec.rb
@@ -223,6 +223,11 @@ describe ::API::V3::Utilities::PathHelper do
end
end
+ describe 'placeholder_users path' do
+ it_behaves_like 'index', :placeholder_user
+ it_behaves_like 'show', :placeholder_user
+ end
+
describe 'posts paths' do
it_behaves_like 'index', :post
it_behaves_like 'show', :post
diff --git a/spec/lib/open_project/enterprise_spec.rb b/spec/lib/open_project/enterprise_spec.rb
index c7d726ab2ce..a30c96582ee 100644
--- a/spec/lib/open_project/enterprise_spec.rb
+++ b/spec/lib/open_project/enterprise_spec.rb
@@ -33,14 +33,17 @@ describe OpenProject::Enterprise, :with_clean_fixture do
describe "#user_limit_reached?" do
let(:user_limit) { 2 }
let(:builtin_user_count) { 2 }
+ # create 3 built-in users, only 2 of which are active
+ # Also create a placeholder user which will not count against the limit
+ let!(:system_user) { User.system }
+ let!(:anonymous_user) { User.anonymous }
+ let!(:deleted_user) { DeletedUser.first } # locked, not active
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
before do
- # create 3 built-in users, only 2 of which are active
- User.system
- User.anonymous
- DeletedUser.first # locked, not active
-
- allow(OpenProject::Enterprise).to receive(:user_limit).and_return(user_limit)
+ allow(OpenProject::Enterprise)
+ .to receive(:user_limit)
+ .and_return(user_limit)
end
context "with fewer active users than the limit allows" do
diff --git a/spec/models/custom_actions/actions/assigned_to_spec.rb b/spec/models/custom_actions/actions/assigned_to_spec.rb
index dd0ecc104b6..bb1c6a32376 100644
--- a/spec/models/custom_actions/actions/assigned_to_spec.rb
+++ b/spec/models/custom_actions/actions/assigned_to_spec.rb
@@ -35,7 +35,7 @@ describe CustomActions::Actions::AssignedTo, type: :model do
users = [FactoryBot.build_stubbed(:user),
FactoryBot.build_stubbed(:group)]
allow(Principal)
- .to receive_message_chain(:active_or_registered, :select, :order_by_name)
+ .to receive_message_chain(:not_locked, :select, :order_by_name)
.and_return(users)
[{ value: nil, label: '-' },
diff --git a/spec/models/custom_actions/actions/notify_spec.rb b/spec/models/custom_actions/actions/notify_spec.rb
index a8c49b90926..7f4b6101163 100644
--- a/spec/models/custom_actions/actions/notify_spec.rb
+++ b/spec/models/custom_actions/actions/notify_spec.rb
@@ -36,7 +36,7 @@ describe CustomActions::Actions::Notify, type: :model do
FactoryBot.build_stubbed(:group)]
allow(Principal)
- .to receive_message_chain(:active_or_registered, :select, :order_by_name)
+ .to receive_message_chain(:not_locked, :select, :order_by_name)
.and_return(users)
[{ value: nil, label: '-' },
@@ -65,7 +65,7 @@ describe CustomActions::Actions::Notify, type: :model do
FactoryBot.build_stubbed(:user)]
allow(Principal)
- .to receive_message_chain(:active_or_registered, :select, :order_by_name, :where)
+ .to receive_message_chain(:not_locked, :select, :order_by_name, :where)
.and_return(principals)
instance.values = principals.map(&:id)
diff --git a/spec/models/custom_actions/actions/responsible_spec.rb b/spec/models/custom_actions/actions/responsible_spec.rb
index feebf583c3a..ee329530b31 100644
--- a/spec/models/custom_actions/actions/responsible_spec.rb
+++ b/spec/models/custom_actions/actions/responsible_spec.rb
@@ -36,7 +36,7 @@ describe CustomActions::Actions::Responsible, type: :model do
FactoryBot.build_stubbed(:group)]
allow(User)
- .to receive_message_chain(:active_or_registered, :select, :order_by_name)
+ .to receive_message_chain(:not_locked, :select, :order_by_name)
.and_return(principals)
[{ value: nil, label: '-' },
diff --git a/spec/models/members/scopes/not_locked_spec.rb b/spec/models/members/scopes/not_locked_spec.rb
new file mode 100644
index 00000000000..83a583dc733
--- /dev/null
+++ b/spec/models/members/scopes/not_locked_spec.rb
@@ -0,0 +1,79 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Members::Scopes::NotLocked, type: :model do
+ let(:project) { FactoryBot.create(:project) }
+ let(:role) { FactoryBot.create(:role) }
+
+ let!(:invited_user_member) do
+ FactoryBot.create(:member,
+ project: project,
+ roles: [role],
+ principal: FactoryBot.create(:user, status: Principal.statuses[:invited]))
+ end
+ let!(:registered_user_member) do
+ FactoryBot.create(:member,
+ project: project,
+ roles: [role],
+ principal: FactoryBot.create(:user, status: Principal.statuses[:registered]))
+ end
+ let!(:locked_user_member) do
+ FactoryBot.create(:member,
+ project: project,
+ roles: [role],
+ principal: FactoryBot.create(:user, status: Principal.statuses[:locked]))
+ end
+ let!(:active_user_member) do
+ FactoryBot.create(:member,
+ project: project,
+ roles: [role],
+ principal: FactoryBot.create(:user, status: Principal.statuses[:active]))
+ end
+ let!(:group_member) do
+ FactoryBot.create(:member,
+ project: project,
+ roles: [role],
+ principal: FactoryBot.create(:group))
+ end
+
+ describe '.fetch' do
+ subject { described_class.fetch }
+
+ it 'returns only actual users and groups' do
+ expect(subject)
+ .to match_array [active_user_member,
+ invited_user_member,
+ registered_user_member,
+ group_member]
+ end
+ end
+end
diff --git a/spec/models/principal_spec.rb b/spec/models/principal_spec.rb
index 3b8df7256e6..5059f5f5cb3 100644
--- a/spec/models/principal_spec.rb
+++ b/spec/models/principal_spec.rb
@@ -52,7 +52,7 @@ describe Principal, type: :model do
end
it 'should not return an inactive user' do
- user.status = User::STATUSES[:locked]
+ user.status = User.statuses[:locked]
user.save!
@@ -61,10 +61,10 @@ describe Principal, type: :model do
end
describe 'active' do
- should_return_groups_and_users_if_active(:active_or_registered)
+ should_return_groups_and_users_if_active(:active)
it 'should not return a registered user' do
- user.status = User::STATUSES[:registered]
+ user.status = User.statuses[:registered]
user.save!
@@ -72,115 +72,15 @@ describe Principal, type: :model do
end
end
- describe 'active_or_registered' do
- should_return_groups_and_users_if_active(:active_or_registered)
+ describe 'not_locked' do
+ should_return_groups_and_users_if_active(:not_locked)
it 'should return a registered user' do
- user.status = User::STATUSES[:registered]
+ user.status = User.statuses[:registered]
user.save!
- expect(Principal.active_or_registered.where(id: user.id)).to eq([user])
- end
- end
-
- describe 'active_or_registered_like' do
- def self.search
- 'blubs'
- end
-
- let(:search) { self.class.search }
-
- before do
- user.lastname = search
- group.lastname = search
- end
-
- should_return_groups_and_users_if_active(:active_or_registered_like, search)
-
- it 'should return a registered user' do
- user.status = User::STATUSES[:registered]
-
- user.save!
-
- expect(Principal.active_or_registered_like(search).where(id: user.id)).to eq([user])
- end
-
- it 'should not return a user if the name does not match' do
- user.save!
-
- expect(Principal.active_or_registered_like(user.lastname + '123').to_a).not_to include(user)
- end
-
- it 'should return a group if the name does match partially' do
- user.save!
-
- expect(Principal.active_or_registered_like(user.lastname[0, -1]).to_a).to include(user)
- end
- end
-
- describe '.not_builtin' do
- let!(:anonymous_user) { FactoryBot.create(:anonymous) }
- let!(:system_user) { FactoryBot.create(:system) }
- let!(:deleted_user) { FactoryBot.create(:deleted_user) }
- let!(:group) { FactoryBot.create(:group) }
- let!(:user) { FactoryBot.create(:user) }
-
- subject { described_class.not_builtin }
-
- it 'returns only actual users and groups', :aggregate_failures do
- expect(subject).to include(user)
- expect(subject).to include(group)
- expect(subject).not_to include(anonymous_user)
- expect(subject).not_to include(system_user)
- expect(subject).not_to include(deleted_user)
- end
- end
-
- context '.like' do
- let!(:login) do
- FactoryBot.create(:principal, login: 'login')
- end
- let!(:login2) do
- FactoryBot.create(:principal, login: 'login2')
- end
- let!(:firstname) do
- FactoryBot.create(:principal, firstname: 'firstname')
- end
- let!(:firstname2) do
- FactoryBot.create(:principal, firstname: 'firstname2')
- end
- let!(:lastname) do
- FactoryBot.create(:principal, lastname: 'lastname')
- end
- let!(:lastname2) do
- FactoryBot.create(:principal, lastname: 'lastname2')
- end
- let!(:mail) do
- FactoryBot.create(:principal, mail: '[email protected]')
- end
- let!(:mail2) do
- FactoryBot.create(:principal, mail: '[email protected]')
- end
-
- it 'finds by login' do
- expect(Principal.like('login'))
- .to match_array [login, login2]
- end
-
- it 'finds by firstname' do
- expect(Principal.like('firstname'))
- .to match_array [firstname, firstname2]
- end
-
- it 'finds by lastname' do
- expect(Principal.like('lastname'))
- .to match_array [lastname, lastname2]
- end
-
- it 'finds by mail' do
- expect(Principal.like('mail'))
- .to match_array [mail, mail2]
+ expect(Principal.not_locked.where(id: user.id)).to eq([user])
end
end
end
diff --git a/spec/models/principals/scopes/human_spec.rb b/spec/models/principals/scopes/human_spec.rb
new file mode 100644
index 00000000000..05329f8c15c
--- /dev/null
+++ b/spec/models/principals/scopes/human_spec.rb
@@ -0,0 +1,49 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Principals::Scopes::Human, type: :model, with_clean_fixture: true do
+ describe '.fetch' do
+ let!(:anonymous_user) { FactoryBot.create(:anonymous) }
+ let!(:system_user) { FactoryBot.create(:system) }
+ let!(:deleted_user) { FactoryBot.create(:deleted_user) }
+ let!(:group) { FactoryBot.create(:group) }
+ let!(:user) { FactoryBot.create(:user) }
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+
+ subject { described_class.fetch }
+
+ it 'returns only actual users and groups' do
+ expect(subject)
+ .to match_array [user, group]
+ end
+ end
+end
diff --git a/spec/models/principals/scopes/like_spec.rb b/spec/models/principals/scopes/like_spec.rb
new file mode 100644
index 00000000000..50cf7e52847
--- /dev/null
+++ b/spec/models/principals/scopes/like_spec.rb
@@ -0,0 +1,80 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Principals::Scopes::Like, type: :model, with_clean_fixture: true do
+ describe '.fetch' do
+ let!(:login) do
+ FactoryBot.create(:principal, login: 'login')
+ end
+ let!(:login2) do
+ FactoryBot.create(:principal, login: 'login2')
+ end
+ let!(:firstname) do
+ FactoryBot.create(:principal, firstname: 'firstname')
+ end
+ let!(:firstname2) do
+ FactoryBot.create(:principal, firstname: 'firstname2')
+ end
+ let!(:lastname) do
+ FactoryBot.create(:principal, lastname: 'lastname')
+ end
+ let!(:lastname2) do
+ FactoryBot.create(:principal, lastname: 'lastname2')
+ end
+ let!(:mail) do
+ FactoryBot.create(:principal, mail: '[email protected]')
+ end
+ let!(:mail2) do
+ FactoryBot.create(:principal, mail: '[email protected]')
+ end
+
+ it 'finds by login' do
+ expect(described_class.fetch('login'))
+ .to match_array [login, login2]
+ end
+
+ it 'finds by firstname' do
+ expect(described_class.fetch('firstname'))
+ .to match_array [firstname, firstname2]
+ end
+
+ it 'finds by lastname' do
+ expect(described_class.fetch('lastname'))
+ .to match_array [lastname, lastname2]
+ end
+
+ it 'finds by mail' do
+ expect(described_class.fetch('mail'))
+ .to match_array [mail, mail2]
+ end
+ end
+end
diff --git a/spec/models/principals/scopes/not_builtin_spec.rb b/spec/models/principals/scopes/not_builtin_spec.rb
new file mode 100644
index 00000000000..13d6fc92236
--- /dev/null
+++ b/spec/models/principals/scopes/not_builtin_spec.rb
@@ -0,0 +1,49 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Principals::Scopes::NotBuiltin, type: :model, with_clean_fixture: true do
+ describe '.fetch' do
+ let!(:anonymous_user) { FactoryBot.create(:anonymous) }
+ let!(:system_user) { FactoryBot.create(:system) }
+ let!(:deleted_user) { FactoryBot.create(:deleted_user) }
+ let!(:group) { FactoryBot.create(:group) }
+ let!(:user) { FactoryBot.create(:user) }
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+
+ subject { described_class.fetch }
+
+ it 'returns only actual users and groups' do
+ expect(subject)
+ .to match_array [user, group, placeholder_user]
+ end
+ end
+end
diff --git a/spec/models/principals/scopes/possible_assignee_spec.rb b/spec/models/principals/scopes/possible_assignee_spec.rb
new file mode 100644
index 00000000000..1c4ef3560b4
--- /dev/null
+++ b/spec/models/principals/scopes/possible_assignee_spec.rb
@@ -0,0 +1,116 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Principals::Scopes::PossibleAssignee, type: :model, with_clean_fixture: true do
+ let(:project) { FactoryBot.create(:project) }
+ let(:other_project) { FactoryBot.create(:project) }
+ let(:role_assignable) { true }
+ let(:role) { FactoryBot.create(:role, assignable: role_assignable) }
+ let(:user_status) { :active }
+ let!(:member_user) do
+ FactoryBot.create(:user,
+ status: user_status,
+ member_in_project: project,
+ member_through_role: role)
+ end
+ let!(:member_placeholder_user) do
+ FactoryBot.create(:placeholder_user,
+ member_in_project: project,
+ member_through_role: role)
+ end
+ let!(:member_group) do
+ FactoryBot.create(:group,
+ member_in_project: project,
+ member_through_role: role)
+ end
+ let!(:other_project_member_user) do
+ FactoryBot.create(:group,
+ member_in_project: other_project,
+ member_through_role: role)
+ end
+
+ describe '.fetch' do
+ subject { described_class.fetch(project) }
+
+ context 'with the role being assignable' do
+ context 'with the user status being active' do
+ it 'returns non locked users, groups and placeholder users that are members' do
+ is_expected
+ .to match_array([member_user,
+ member_placeholder_user,
+ member_group])
+ end
+ end
+
+ context 'with the user status being registered' do
+ let(:user_status) { :registered }
+
+ it 'returns non locked users, groups and placeholder users that are members' do
+ is_expected
+ .to match_array([member_user,
+ member_placeholder_user,
+ member_group])
+ end
+ end
+
+ context 'with the user status being invited' do
+ let(:user_status) { :invited }
+
+ it 'returns non locked users, groups and placeholder users that are members' do
+ is_expected
+ .to match_array([member_user,
+ member_placeholder_user,
+ member_group])
+ end
+ end
+
+ context 'with the user status being locked' do
+ let(:user_status) { :locked }
+
+ it 'returns non locked users, groups and placeholder users that are members' do
+ is_expected
+ .to match_array([member_placeholder_user,
+ member_group])
+ end
+ end
+ end
+
+ context 'with the role not being assignable' do
+ let(:role_assignable) { false }
+
+ it 'returns nothing' do
+ is_expected
+ .to be_empty
+ end
+ end
+ end
+end
diff --git a/spec/models/principals/scopes/possible_member_spec.rb b/spec/models/principals/scopes/possible_member_spec.rb
new file mode 100644
index 00000000000..c72075fc415
--- /dev/null
+++ b/spec/models/principals/scopes/possible_member_spec.rb
@@ -0,0 +1,71 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Principals::Scopes::PossibleMember, type: :model, with_clean_fixture: true do
+ let(:project) { FactoryBot.create(:project) }
+ let(:role) { FactoryBot.create(:role) }
+ let!(:active_user) { FactoryBot.create(:user) }
+ let!(:locked_user) { FactoryBot.create(:user, status: :locked) }
+ let!(:registered_user) { FactoryBot.create(:user, status: :registered) }
+ let!(:invited_user) { FactoryBot.create(:user, status: :invited) }
+ let!(:anonymous_user) { FactoryBot.create(:anonymous) }
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+ let!(:group) { FactoryBot.create(:group) }
+ let!(:member_user) do
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_through_role: role)
+ end
+ let!(:member_placeholder_user) do
+ FactoryBot.create(:placeholder_user,
+ member_in_project: project,
+ member_through_role: role)
+ end
+ let!(:member_group) do
+ FactoryBot.create(:group,
+ member_in_project: project,
+ member_through_role: role)
+ end
+
+ describe '.fetch' do
+ subject { described_class.fetch(project) }
+
+ it 'returns non locked users, groups and placeholder users not part of the project yet' do
+ is_expected
+ .to match_array([active_user,
+ registered_user,
+ invited_user,
+ placeholder_user,
+ group])
+ end
+ end
+end
diff --git a/spec/models/principals/scopes/user_spec.rb b/spec/models/principals/scopes/user_spec.rb
new file mode 100644
index 00000000000..627f22ff3cd
--- /dev/null
+++ b/spec/models/principals/scopes/user_spec.rb
@@ -0,0 +1,49 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Principals::Scopes::User, type: :model, with_clean_fixture: true do
+ describe '.fetch' do
+ let!(:anonymous_user) { FactoryBot.create(:anonymous) }
+ let!(:system_user) { FactoryBot.create(:system) }
+ let!(:deleted_user) { FactoryBot.create(:deleted_user) }
+ let!(:group) { FactoryBot.create(:group) }
+ let!(:user) { FactoryBot.create(:user) }
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+
+ subject { described_class.fetch }
+
+ it 'returns only actual users and groups' do
+ expect(subject)
+ .to match_array [user]
+ end
+ end
+end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index b9819b333f6..809e470d0ac 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -118,40 +118,6 @@ describe Project, type: :model do
end
end
- describe 'available principles' do
- let(:user) { FactoryBot.create(:user) }
- let(:group) { FactoryBot.create(:group) }
- let(:role) { FactoryBot.create(:role) }
- let!(:user_member) do
- FactoryBot.create(:member,
- principal: user,
- project: project,
- roles: [role])
- end
- let!(:group_member) do
- FactoryBot.create(:member,
- principal: group,
- project: project,
- roles: [role])
- end
-
- shared_examples_for 'returning groups and users' do
- it { is_expected.to match_array([user, group]) }
- end
-
- describe 'assignees' do
- subject { project.possible_assignees }
-
- it_behaves_like 'returning groups and users'
- end
-
- describe 'responsibles' do
- subject { project.possible_responsibles }
-
- it_behaves_like 'returning groups and users'
- end
- end
-
describe 'status' do
let(:status) { FactoryBot.build_stubbed(:project_status) }
let(:stubbed_project) do
diff --git a/spec/models/queries/members/filters/principal_filter_spec.rb b/spec/models/queries/members/filters/principal_filter_spec.rb
index 0e885cb21ac..9b09517353f 100644
--- a/spec/models/queries/members/filters/principal_filter_spec.rb
+++ b/spec/models/queries/members/filters/principal_filter_spec.rb
@@ -41,7 +41,7 @@ describe Queries::Members::Filters::PrincipalFilter, type: :model do
principal_scope = double('principal scope')
allow(Principal)
- .to receive(:active_or_registered)
+ .to receive(:not_locked)
.and_return(principal_scope)
allow(principal_scope)
diff --git a/spec/models/queries/members/filters/status_filter_spec.rb b/spec/models/queries/members/filters/status_filter_spec.rb
index 2b00196cedc..784ec7dde92 100644
--- a/spec/models/queries/members/filters/status_filter_spec.rb
+++ b/spec/models/queries/members/filters/status_filter_spec.rb
@@ -37,7 +37,7 @@ describe Queries::Members::Filters::StatusFilter, type: :model do
describe '#allowed_values' do
it 'is a list of the possible values' do
- expected = Principal::STATUSES.keys.map do |key|
+ expected = Principal.statuses.keys.map do |key|
[I18n.t(:"status_#{key}"), key]
end
diff --git a/spec/models/queries/users/filters/any_name_attribute_filter_spec.rb b/spec/models/queries/users/filters/any_name_attribute_filter_spec.rb
index dc9609c1254..ebc0a4d6814 100644
--- a/spec/models/queries/users/filters/any_name_attribute_filter_spec.rb
+++ b/spec/models/queries/users/filters/any_name_attribute_filter_spec.rb
@@ -33,13 +33,13 @@ require 'spec_helper'
describe Queries::Users::Filters::AnyNameAttributeFilter, type: :model do
include_context 'filter tests'
let(:values) { ['A name'] }
- let(:model) { User }
+ let(:model) { User.user }
let(:filter_str) { instance.send :sql_concat_name }
it_behaves_like 'basic query filter' do
let(:class_key) { :any_name_attribute }
let(:type) { :string }
- let(:model) { User }
+ let(:model) { User.user }
describe '#allowed_values' do
it 'is nil' do
diff --git a/spec/models/queries/users/filters/group_filter_spec.rb b/spec/models/queries/users/filters/group_filter_spec.rb
index eec9c4c3c71..ef2108ee510 100644
--- a/spec/models/queries/users/filters/group_filter_spec.rb
+++ b/spec/models/queries/users/filters/group_filter_spec.rb
@@ -56,7 +56,7 @@ describe Queries::Users::Filters::GroupFilter, type: :model do
end
it_behaves_like 'list_optional group query filter' do
- let(:model) { User }
+ let(:model) { User.user }
let(:valid_values) { [group1.id.to_s] }
end
end
diff --git a/spec/models/queries/users/filters/name_filter_spec.rb b/spec/models/queries/users/filters/name_filter_spec.rb
index 6759780917d..4ab8f31a07b 100644
--- a/spec/models/queries/users/filters/name_filter_spec.rb
+++ b/spec/models/queries/users/filters/name_filter_spec.rb
@@ -33,12 +33,12 @@ require 'spec_helper'
describe Queries::Users::Filters::NameFilter, type: :model do
include_context 'filter tests'
let(:values) { ['A name'] }
- let(:model) { User }
+ let(:model) { User.user }
it_behaves_like 'basic query filter' do
let(:class_key) { :name }
let(:type) { :string }
- let(:model) { User }
+ let(:model) { User.user }
describe '#allowed_values' do
it 'is nil' do
diff --git a/spec/models/queries/users/filters/status_filter_spec.rb b/spec/models/queries/users/filters/status_filter_spec.rb
index 007ba9da729..bb375f4d15b 100644
--- a/spec/models/queries/users/filters/status_filter_spec.rb
+++ b/spec/models/queries/users/filters/status_filter_spec.rb
@@ -37,7 +37,7 @@ describe Queries::Users::Filters::StatusFilter, type: :model do
describe '#allowed_values' do
it 'is a list of the possible values' do
- expected = Principal::STATUSES.keys.map do |key|
+ expected = Principal.statuses.keys.map do |key|
[I18n.t(:"status_#{key}"), key]
end
@@ -49,7 +49,7 @@ describe Queries::Users::Filters::StatusFilter, type: :model do
describe '#scope' do
include_context 'filter tests'
let(:values) { %w[active invited] }
- let(:model) { User }
+ let(:model) { User.user }
context 'for "="' do
let(:operator) { '=' }
diff --git a/spec/models/queries/users/user_query_spec.rb b/spec/models/queries/users/user_query_spec.rb
index 047d2f7e9b5..59d0f14271f 100644
--- a/spec/models/queries/users/user_query_spec.rb
+++ b/spec/models/queries/users/user_query_spec.rb
@@ -28,12 +28,12 @@
require 'spec_helper'
# prevents test failures where the system user
-# is mentioned in the User.not_builtin scope
+# is mentioned in the User.user scope
require 'system_user'
describe Queries::Users::UserQuery, type: :model do
let(:instance) { described_class.new }
- let(:base_scope) { User.not_builtin.order(id: :desc) }
+ let(:base_scope) { User.user.order(id: :desc) }
context 'without a filter' do
describe '#results' do
@@ -52,8 +52,9 @@ describe Queries::Users::UserQuery, type: :model do
it 'is the same as handwriting the query' do
expected = base_scope
.merge(User
- .where(["LOWER(CONCAT(users.firstname, CONCAT(' ', users.lastname))) LIKE ?",
- "%a user%"]))
+ .user
+ .where(["LOWER(CONCAT(users.firstname, CONCAT(' ', users.lastname))) LIKE ?",
+ "%a user%"]))
expect(instance.results.to_sql).to eql expected.to_sql
end
@@ -78,7 +79,7 @@ describe Queries::Users::UserQuery, type: :model do
describe '#results' do
it 'is the same as handwriting the query' do
- expected = base_scope.merge(User.where("users.status IN (1)"))
+ expected = base_scope.merge(User.user.where("users.status IN (1)"))
expect(instance.results.to_sql).to eql expected.to_sql
end
@@ -115,6 +116,7 @@ describe Queries::Users::UserQuery, type: :model do
it 'is the same as handwriting the query' do
expected = base_scope
.merge(User
+ .user
.where(["users.id IN (#{User.in_group([group_1.id.to_s]).select(:id).to_sql})"]))
expect(instance.results.to_sql).to eql expected.to_sql
@@ -166,7 +168,7 @@ describe Queries::Users::UserQuery, type: :model do
describe '#results' do
it 'is the same as handwriting the query' do
- expected = User.not_builtin.merge(User.order(id: :asc))
+ expected = User.user.merge(User.order(id: :asc))
expect(instance.results.to_sql).to eql expected.to_sql
end
@@ -180,7 +182,7 @@ describe Queries::Users::UserQuery, type: :model do
describe '#results' do
it 'is the same as handwriting the query' do
- expected = User.not_builtin.merge(User.order_by_name.reverse_order).order(id: :desc)
+ expected = User.user.merge(User.order_by_name.reverse_order).order(id: :desc)
expect(instance.results.to_sql).to eql expected.to_sql
end
@@ -194,7 +196,7 @@ describe Queries::Users::UserQuery, type: :model do
describe '#results' do
it 'is the same as handwriting the query' do
- expected = User.not_builtin.merge(User.joins(:groups).order("groups_users.lastname DESC")).order(id: :desc)
+ expected = User.user.merge(User.joins(:groups).order("groups_users.lastname DESC")).order(id: :desc)
expect(instance.results.to_sql).to eql expected.to_sql
end
diff --git a/spec/models/queries/work_packages/filter/principal_loader_spec.rb b/spec/models/queries/work_packages/filter/principal_loader_spec.rb
index 4c0925484e7..08829185f77 100644
--- a/spec/models/queries/work_packages/filter/principal_loader_spec.rb
+++ b/spec/models/queries/work_packages/filter/principal_loader_spec.rb
@@ -77,7 +77,7 @@ describe Queries::WorkPackages::Filter::PrincipalLoader, type: :model do
before do
allow(Principal)
- .to receive_message_chain(:active_or_registered, :in_visible_project)
+ .to receive_message_chain(:not_locked, :in_visible_project)
.and_return(matching_principals)
end
diff --git a/spec/models/system_user_spec.rb b/spec/models/system_user_spec.rb
index 469cb0f98d5..37a966b0d81 100644
--- a/spec/models/system_user_spec.rb
+++ b/spec/models/system_user_spec.rb
@@ -34,7 +34,7 @@ describe SystemUser, type: :model do
describe '#grant_privileges' do
before do
expect(system_user.admin).to be_falsey
- expect(system_user.status).to eq(User::STATUSES[:active])
+ expect(system_user).to be_active
system_user.grant_privileges
end
@@ -61,15 +61,15 @@ describe SystemUser, type: :model do
let(:role) { FactoryBot.create(:role, permissions: [:view_work_packages]) }
let(:member) {
FactoryBot.build(:member, project: project,
- roles: [role],
- principal: user)
+ roles: [role],
+ principal: user)
}
let(:status) { FactoryBot.create(:status) }
let(:issue) {
FactoryBot.build(:work_package, type: project.types.first,
- author: user,
- project: project,
- status: status)
+ author: user,
+ project: project,
+ status: status)
}
before do
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 92ae1c8b793..0e6d1baffdc 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -45,22 +45,6 @@ describe User, type: :model do
status: status)
end
- describe '.not_builtin' do
- let!(:anonymous_user) { FactoryBot.create(:anonymous) }
- let!(:system_user) { FactoryBot.create(:system) }
- let!(:deleted_user) { FactoryBot.create(:deleted_user) }
- let!(:user) { FactoryBot.create(:user) }
-
- subject { described_class.not_builtin }
-
- it 'returns only actual users', :aggregate_failures do
- expect(subject).to include(user)
- expect(subject).not_to include(anonymous_user)
- expect(subject).not_to include(system_user)
- expect(subject).not_to include(deleted_user)
- end
- end
-
describe 'a user with a long login (<= 256 chars)' do
let(:login) { 'a' * 256 }
it 'is valid' do
@@ -495,7 +479,7 @@ describe User, type: :model do
context 'default admin account was disabled' do
before do
- default_admin.status = User::STATUSES[:locked]
+ default_admin.status = User.statuses[:locked]
default_admin.save
end
@@ -549,7 +533,7 @@ describe User, type: :model do
end
it 'is false for an inactive user' do
- user.status = User::STATUSES[:locked]
+ user.status = User.statuses[:locked]
user.mail_notification = 'all'
expect(user.notify_about?({})).to be_falsey
end
diff --git a/spec/models/users/scopes/newest_spec.rb b/spec/models/users/scopes/newest_spec.rb
new file mode 100644
index 00000000000..cecedccc2c2
--- /dev/null
+++ b/spec/models/users/scopes/newest_spec.rb
@@ -0,0 +1,51 @@
+#-- encoding: UTF-8
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2021 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+describe Users::Scopes::Newest, type: :model, with_clean_fixture: true do
+ describe '.fetch' do
+ let!(:anonymous_user) { FactoryBot.create(:anonymous) }
+ let!(:system_user) { FactoryBot.create(:system) }
+ let!(:deleted_user) { FactoryBot.create(:deleted_user) }
+ let!(:group) { FactoryBot.create(:group) }
+ let!(:user1) { FactoryBot.create(:user) }
+ let!(:user2) { FactoryBot.create(:user) }
+ let!(:user3) { FactoryBot.create(:user) }
+ let!(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+
+ subject { described_class.fetch }
+
+ it 'returns only actual users ordered by creation date desc' do
+ expect(subject.to_a)
+ .to eql [user3, user2, user1]
+ end
+ end
+end
diff --git a/spec/models/watcher_spec.rb b/spec/models/watcher_spec.rb
index d51cde2ad0a..337e1fa43d2 100644
--- a/spec/models/watcher_spec.rb
+++ b/spec/models/watcher_spec.rb
@@ -59,12 +59,12 @@ describe Watcher, type: :model, with_mail: false do
end
it 'is valid for an invited user' do
- user.status = Principal::STATUSES[:invited]
+ user.status = Principal.statuses[:invited]
expect(watcher).to be_valid
end
it 'is valid for a registered user' do
- user.status = Principal::STATUSES[:registered]
+ user.status = Principal.statuses[:registered]
expect(watcher).to be_valid
end
end
diff --git a/spec/models/work_package_spec.rb b/spec/models/work_package_spec.rb
index 911d1b46572..aaafdff685c 100644
--- a/spec/models/work_package_spec.rb
+++ b/spec/models/work_package_spec.rb
@@ -156,34 +156,6 @@ describe WorkPackage, type: :model do
it { is_expected.to eq(category.assigned_to) }
end
- describe '#assignable_assignees' do
- let(:value) { double('value') }
-
- before do
- allow(stub_work_package.project).to receive(:possible_assignees).and_return(value)
- end
-
- subject { stub_work_package.assignable_assignees }
-
- it 'calls project#possible_assignees and returns the value' do
- is_expected.to eql(value)
- end
- end
-
- describe '#assignable_responsibles' do
- let(:value) { double('value') }
-
- before do
- allow(stub_work_package.project).to receive(:possible_responsibles).and_return(value)
- end
-
- subject { stub_work_package.assignable_responsibles }
-
- it 'calls project#possible_responsibles and returns the value' do
- is_expected.to eql(value)
- end
- end
-
describe 'responsible' do
let(:group) { FactoryBot.create(:group) }
diff --git a/spec/requests/api/v3/membership_resources_spec.rb b/spec/requests/api/v3/membership_resources_spec.rb
index a89e939f97e..a4a5e9cad4c 100644
--- a/spec/requests/api/v3/membership_resources_spec.rb
+++ b/spec/requests/api/v3/membership_resources_spec.rb
@@ -192,6 +192,37 @@ describe 'API v3 memberships resource', type: :request, content_type: :json do
end
end
+ context 'with a placeholder_user' do
+ let(:placeholder_user) do
+ FactoryBot.create(:placeholder_user)
+ end
+ let(:placeholder_member) do
+ FactoryBot.create(:member,
+ roles: [FactoryBot.create(:role)],
+ project: project,
+ principal: placeholder_user)
+ end
+ let(:members) { [own_member, placeholder_member] }
+
+ it 'returns that placeholder user membership together with the rest of them' do
+ expect(subject.body)
+ .to be_json_eql('Collection'.to_json)
+ .at_path('_type')
+
+ expect(subject.body)
+ .to be_json_eql('2')
+ .at_path('total')
+
+ expect(subject.body)
+ .to be_json_eql(own_member.id.to_json)
+ .at_path('_embedded/elements/0/id')
+
+ expect(subject.body)
+ .to be_json_eql(placeholder_member.id.to_json)
+ .at_path('_embedded/elements/1/id')
+ end
+ end
+
context 'filtering by user name' do
let(:filters) do
[{ 'any_name_attribute' => {
@@ -415,6 +446,29 @@ describe 'API v3 memberships resource', type: :request, content_type: :json do
end
end
+ context 'for a placeholder user' do
+ it_behaves_like 'successful member creation' do
+ let(:placeholder_user) { FactoryBot.create(:placeholder_user) }
+ let(:principal) { placeholder_user }
+ let(:principal_path) { api_v3_paths.placeholder_user(placeholder_user.id) }
+ let(:body) do
+ {
+ project: {
+ href: api_v3_paths.project(project.id)
+ },
+ principal: {
+ href: principal_path
+ },
+ roles: [
+ {
+ href: api_v3_paths.role(other_role.id)
+ }
+ ]
+ }.to_json
+ end
+ end
+ end
+
context 'for a global membership' do
let(:expected_role) { global_role }
let(:body) do
@@ -500,7 +554,7 @@ describe 'API v3 memberships resource', type: :request, content_type: :json do
expect(last_response.status).to eq(422)
error_message = "For property 'user' a link like '/api/v3/groups/:id' or " +
- "'/api/v3/users/:id' is expected, but got '#{api_v3_paths.role(other_user.id)}'."
+ "'/api/v3/users/:id' or '/api/v3/placeholder_users/:id' is expected, but got '#{api_v3_paths.role(other_user.id)}'."
expect(last_response.body)
.to be_json_eql(error_message.to_json)
diff --git a/spec/requests/api/v3/principals/principals_resource_spec.rb b/spec/requests/api/v3/principals/principals_resource_spec.rb
index 2eb6ff67e81..6c0b3ca30cf 100644
--- a/spec/requests/api/v3/principals/principals_resource_spec.rb
+++ b/spec/requests/api/v3/principals/principals_resource_spec.rb
@@ -58,43 +58,45 @@ describe 'API v3 Principals resource', type: :request do
let(:permissions) { [] }
let(:user) do
user = FactoryBot.create(:user,
- member_in_project: project,
- member_through_role: role,
- lastname: 'aaaa')
+ member_in_project: project,
+ member_through_role: role,
+ lastname: 'Aaaa')
other_project.add_member! user, role
user
end
- let(:other_user) do
+ let!(:other_user) do
FactoryBot.create(:user,
- member_in_project: other_project,
- member_through_role: role,
- lastname: 'bbbb')
+ member_in_project: other_project,
+ member_through_role: role,
+ lastname: 'Bbbb')
end
- let(:user_in_non_member_project) do
+ let!(:user_in_non_member_project) do
FactoryBot.create(:user,
- member_in_project: non_member_project,
- member_through_role: role,
- lastname: 'cccc')
+ member_in_project: non_member_project,
+ member_through_role: role,
+ lastname: 'Cccc')
end
- let(:group) do
+ let!(:group) do
group = FactoryBot.create(:group,
- lastname: 'gggg')
+ lastname: 'Gggg')
project.add_member! group, role
user
end
+ let!(:placeholder_user) do
+ placeholder = FactoryBot.create(:placeholder_user,
+ name: 'Pppp')
- before do
- allow(User)
- .to receive(:current)
- .and_return(user)
+ project.add_member! placeholder, role
- other_user
- user_in_non_member_project
- group
+ user
+ end
+
+ before do
+ login_as(user)
get path
end
@@ -104,13 +106,20 @@ describe 'API v3 Principals resource', type: :request do
.to eql(200)
end
- it_behaves_like 'API V3 collection response', 3, 3, 'User' do
+ it_behaves_like 'API V3 collection response', 4, 4, 'User' do
let(:response) { last_response }
- it 'has the group as the last element' do
+ # The order_by_name scope currently has a bug in that it does not correctly handle
+ # null values (no first names for group and placeholder users) in the db.
+ # A user would expect placeholder and user to be sorted the other way around.
+ it 'has the group as the last and the placeholder as the second to last element' do
is_expected
- .to be_json_eql('Group'.to_json)
+ .to be_json_eql('PlaceholderUser'.to_json)
.at_path('_embedded/elements/2/_type')
+
+ is_expected
+ .to be_json_eql('Group'.to_json)
+ .at_path('_embedded/elements/3/_type')
end
end
@@ -119,7 +128,7 @@ describe 'API v3 Principals resource', type: :request do
[{ member: { operator: '=', values: [project.id.to_s] } }]
end
- it_behaves_like 'API V3 collection response', 2, 2, 'User' do
+ it_behaves_like 'API V3 collection response', 3, 3, 'User' do
let(:response) { last_response }
end
end
@@ -144,6 +153,16 @@ describe 'API v3 Principals resource', type: :request do
end
end
+ context 'provide filter for type "PlaceholderUser"' do
+ let(:filter) do
+ [{ type: { operator: '=', values: ['PlaceholderUser'] } }]
+ end
+
+ it_behaves_like 'API V3 collection response', 1, 1, 'PlaceholderUser' do
+ let(:response) { last_response }
+ end
+ end
+
context 'user without a project membership' do
let(:user) { FactoryBot.create(:user) }
diff --git a/spec/requests/api/v3/user/filters_spec.rb b/spec/requests/api/v3/user/filters_spec.rb
index 777fab2fb8c..7b73cdfafaf 100644
--- a/spec/requests/api/v3/user/filters_spec.rb
+++ b/spec/requests/api/v3/user/filters_spec.rb
@@ -34,10 +34,10 @@ describe 'GET /api/v3/users',
type: :request do
let!(:users) do
[
- FactoryBot.create(:admin, login: 'admin', status: Principal::STATUSES[:active]),
- FactoryBot.create(:user, login: 'h.wurst', status: Principal::STATUSES[:active]),
- FactoryBot.create(:user, login: 'h.heine', status: Principal::STATUSES[:locked]),
- FactoryBot.create(:user, login: 'm.mario', status: Principal::STATUSES[:active])
+ FactoryBot.create(:admin, login: 'admin', status: :active),
+ FactoryBot.create(:user, login: 'h.wurst', status: :active),
+ FactoryBot.create(:user, login: 'h.heine', status: :locked),
+ FactoryBot.create(:user, login: 'm.mario', status: :active)
]
end
diff --git a/spec/requests/api/v3/user/user_resource_spec.rb b/spec/requests/api/v3/user/user_resource_spec.rb
index 932c0f77bc7..6cb3ae2ab40 100644
--- a/spec/requests/api/v3/user/user_resource_spec.rb
+++ b/spec/requests/api/v3/user/user_resource_spec.rb
@@ -39,7 +39,7 @@ describe 'API v3 User resource',
let(:current_user) { FactoryBot.create(:user) }
let(:user) { FactoryBot.create(:user) }
let(:admin) { FactoryBot.create(:admin) }
- let(:locked_admin) { FactoryBot.create :admin, status: Principal::STATUSES[:locked] }
+ let(:locked_admin) { FactoryBot.create :admin, status: Principal.statuses[:locked] }
let(:user_with_global_add_user) do
user = FactoryBot.create(:user, firstname: 'Global', lastname: 'User')
global_role = FactoryBot.create :global_role, name: 'Add user', permissions: %i[add_user]
@@ -125,7 +125,7 @@ describe 'API v3 User resource',
context 'on sorting' do
let(:users_by_name_order) do
- User.not_builtin.order_by_name.reverse_order
+ User.human.order_by_name.reverse_order
end
let(:get_path) do
diff --git a/spec/requests/api/v3/user/userlock_resource_spec.rb b/spec/requests/api/v3/user/userlock_resource_spec.rb
index be55ef6d32c..a495850562a 100644
--- a/spec/requests/api/v3/user/userlock_resource_spec.rb
+++ b/spec/requests/api/v3/user/userlock_resource_spec.rb
@@ -34,7 +34,7 @@ describe 'API v3 UserLock resource', type: :request, content_type: :json do
include API::V3::Utilities::PathHelper
let(:current_user) { FactoryBot.build_stubbed(:user) }
- let(:user) { FactoryBot.create(:user, status: User::STATUSES[:active]) }
+ let(:user) { FactoryBot.create(:user, status: User.statuses[:active]) }
let(:model) { ::API::V3::Users::UserModel.new(user) }
let(:representer) { ::API::V3::Users::UserRepresenter.new(model) }
let(:lock_path) { api_v3_paths.user_lock user.id }
@@ -64,7 +64,7 @@ describe 'API v3 UserLock resource', type: :request, content_type: :json do
context 'user account is incompatible' do
let(:user) {
- FactoryBot.create(:user, status: User::STATUSES[:registered])
+ FactoryBot.create(:user, status: User.statuses[:registered])
}
it 'should fail for invalid transitions' do
expect(subject.status).to eq(400)
@@ -111,7 +111,7 @@ describe 'API v3 UserLock resource', type: :request, content_type: :json do
context 'user account is incompatible' do
let(:user) {
- FactoryBot.create(:user, status: User::STATUSES[:registered])
+ FactoryBot.create(:user, status: User.statuses[:registered])
}
it 'should fail for invalid transitions' do
expect(subject.status).to eq(400)
diff --git a/spec/requests/api/v3/watcher_resource_spec.rb b/spec/requests/api/v3/watcher_resource_spec.rb
index 8ee4fa30cef..6d7dee0fd65 100644
--- a/spec/requests/api/v3/watcher_resource_spec.rb
+++ b/spec/requests/api/v3/watcher_resource_spec.rb
@@ -43,25 +43,25 @@ describe 'API v3 Watcher resource', type: :request, content_type: :json do
let(:work_package) { FactoryBot.create(:work_package, project: project) }
let(:available_watcher) do
FactoryBot.create :user,
- firstname: 'Something',
- lastname: 'Strange',
- member_in_project: project,
- member_through_role: view_work_packages_role
+ firstname: 'Something',
+ lastname: 'Strange',
+ member_in_project: project,
+ member_through_role: view_work_packages_role
end
let(:watching_user) do
FactoryBot.create :user,
- member_in_project: project,
- member_through_role: view_work_packages_role
+ member_in_project: project,
+ member_through_role: view_work_packages_role
end
let(:existing_watcher) do
FactoryBot.create(:watcher, watchable: work_package, user: watching_user)
end
let!(:watching_blocked_user) do
- FactoryBot.create :user,
+ FactoryBot.create :user,
login: 'lockedUser',
- mail: '[email protected]',
member_in_project: project,
member_through_role: view_work_packages_role
end
diff --git a/spec/requests/api/v3/work_package_resource_spec.rb b/spec/requests/api/v3/work_package_resource_spec.rb
index 1b83b4b10a5..d0dca06ff60 100644
--- a/spec/requests/api/v3/work_package_resource_spec.rb
+++ b/spec/requests/api/v3/work_package_resource_spec.rb
@@ -759,7 +759,7 @@ describe 'API v3 Work package resource',
responsible: current_user)
end
- before { allow(User).to receive(:current).and_return current_user }
+ before { login_as current_user }
shared_context 'setup group membership' do
let(:group) { FactoryBot.create(:group) }
@@ -772,6 +772,12 @@ describe 'API v3 Work package resource',
end
end
+ let(:placeholder_user) do
+ FactoryBot.create(:placeholder_user,
+ member_in_project: project,
+ member_through_role: role)
+ end
+
shared_examples_for 'handling people' do |property|
let(:user_parameter) { { _links: { property => { href: user_href } } } }
let(:href_path) { "_links/#{property}/href" }
@@ -795,8 +801,9 @@ describe 'API v3 Work package resource',
it { expect(response.status).to eq(200) }
it {
- expect(response.body).to be_json_eql(title)
- .at_path("_links/#{property}/title")
+ expect(response.body)
+ .to be_json_eql(title)
+ .at_path("_links/#{property}/title")
}
it_behaves_like 'lock version updated'
@@ -822,6 +829,16 @@ describe 'API v3 Work package resource',
let(:assigned_user) { group }
end
end
+
+ context 'placeholder user' do
+ let(:user_href) { api_v3_paths.placeholder_user placeholder_user.id }
+
+ include_context 'patch request'
+
+ it_behaves_like 'valid user assignment' do
+ let(:assigned_user) { placeholder_user }
+ end
+ end
end
describe 'invalid' do
@@ -860,7 +877,7 @@ describe 'API v3 Work package resource',
let(:message) do
I18n.t('api_v3.errors.invalid_resource',
property: property,
- expected: "/api/v3/groups/:id' or '/api/v3/users/:id",
+ expected: "/api/v3/groups/:id' or '/api/v3/users/:id' or '/api/v3/placeholder_users/:id",
actual: user_href)
end
end
diff --git a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb
index 18ef95b8c7e..899dc2e69d3 100644
--- a/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb
@@ -454,6 +454,18 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
it_behaves_like 'valid user assignment'
end
+
+ context 'existing placeholder_user' do
+ let(:user_link) { api_v3_paths.placeholder_user placeholder_user.id }
+ let(:role) { FactoryBot.create(:role) }
+ let(:placeholder_user) do
+ FactoryBot.create(:placeholder_user,
+ member_in_project: project,
+ member_through_role: role)
+ end
+
+ it_behaves_like 'valid user assignment'
+ end
end
context "invalid #{property}" do
@@ -478,7 +490,7 @@ describe 'API v3 Work package form resource', type: :request, with_mail: false d
let(:message) do
I18n.t('api_v3.errors.invalid_resource',
property: property,
- expected: "/api/v3/groups/:id' or '/api/v3/users/:id",
+ expected: "/api/v3/groups/:id' or '/api/v3/users/:id' or '/api/v3/placeholder_users/:id",
actual: user_link)
end
end
diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rb
index e5033d8eac6..9aa5d676643 100644
--- a/spec/services/projects/copy_service_integration_spec.rb
+++ b/spec/services/projects/copy_service_integration_spec.rb
@@ -287,12 +287,13 @@ describe Projects::CopyService, 'integration', type: :model do
query.add_filter('parent', '=', [source_wp.id.to_s])
# Not valid due to wp not visible
query.save!(validate: false)
+ query
end
- it 'produces a valid query that is mapepd in the new project' do
+ it 'produces a valid query that is mapped in the new project' do
expect(subject).to be_success
copied_wp = project_copy.work_packages.find_by(subject: 'source wp')
- copied = project_copy.queries.first
+ copied = project_copy.queries.find_by(name: query.name)
expect(copied.filters[1].values).to eq [copied_wp.id.to_s]
end
end
diff --git a/spec/services/users/register_user_service_spec.rb b/spec/services/users/register_user_service_spec.rb
index 856c9bb9b78..f5879125624 100644
--- a/spec/services/users/register_user_service_spec.rb
+++ b/spec/services/users/register_user_service_spec.rb
@@ -45,7 +45,7 @@ describe Users::RegisterUserService do
describe '#register_invited_user' do
it 'tries to activate that user regardless of settings' do
with_all_registration_options do |_type|
- user = User.new(status: Principal::STATUSES[:invited])
+ user = User.new(status: Principal.statuses[:invited])
instance = described_class.new(user)
expect(user).to receive(:activate)
@@ -62,7 +62,7 @@ describe Users::RegisterUserService do
describe '#register_ldap_user' do
it 'tries to activate that user regardless of settings' do
with_all_registration_options do |_type|
- user = User.new(status: Principal::STATUSES[:registered])
+ user = User.new(status: Principal.statuses[:registered])
instance = described_class.new(user)
allow(user).to receive(:auth_source_id).and_return 1234
diff --git a/spec/support/api/v3/shared_available_principals_examples.rb b/spec/support/api/v3/shared_available_principals_examples.rb
index f29f4e5e7ce..cb662ef6dcc 100644
--- a/spec/support/api/v3/shared_available_principals_examples.rb
+++ b/spec/support/api/v3/shared_available_principals_examples.rb
@@ -32,10 +32,14 @@ shared_examples_for 'available principals' do |principals|
include API::V3::Utilities::PathHelper
let(:current_user) do
- FactoryBot.create(:user, member_in_project: project, member_through_role: role)
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_through_role: role)
end
let(:other_user) do
- FactoryBot.create(:user, member_in_project: project, member_through_role: role)
+ FactoryBot.create(:user,
+ member_in_project: project,
+ member_through_role: role)
end
let(:role) { FactoryBot.create(:role, permissions: permissions) }
let(:project) { FactoryBot.create(:project) }
@@ -44,6 +48,11 @@ shared_examples_for 'available principals' do |principals|
project.add_member! group, FactoryBot.create(:role)
group
end
+ let(:placeholder_user) do
+ FactoryBot.create(:placeholder_user,
+ member_in_project: project,
+ member_through_role: role)
+ end
let(:permissions) { [:view_work_packages] }
shared_context "request available #{principals}" do
@@ -51,7 +60,7 @@ shared_examples_for 'available principals' do |principals|
end
before do
- allow(User).to receive(:current).and_return(current_user)
+ login_as(current_user)
end
describe 'response' do
@@ -84,6 +93,13 @@ shared_examples_for 'available principals' do |principals|
# current user and group
it_behaves_like "returns available #{principals}", 2, 2, 'Group'
end
+
+ describe 'placeholder users' do
+ let!(:users) { [placeholder_user] }
+
+ # current user and placeholder user
+ it_behaves_like "returns available #{principals}", 2, 2, 'PlaceholderUser'
+ end
end
describe 'if not allowed' do
diff --git a/spec/support/shared/acts_as_watchable.rb b/spec/support/shared/acts_as_watchable.rb
index 8439d6a67db..ebf9d305524 100644
--- a/spec/support/shared/acts_as_watchable.rb
+++ b/spec/support/shared/acts_as_watchable.rb
@@ -49,14 +49,14 @@ MESSAGE
let(:non_member_user) { FactoryBot.create(:user) }
let(:user_with_permission) do
FactoryBot.create(:user,
- member_in_project: project,
- member_through_role: watcher_role)
+ member_in_project: project,
+ member_through_role: watcher_role)
end
let(:locked_user_with_permission) do
FactoryBot.create(:user,
- status: Principal::STATUSES[:locked],
- member_in_project: project,
- member_through_role: watcher_role)
+ status: Principal.statuses[:locked],
+ member_in_project: project,
+ member_through_role: watcher_role)
end
let(:user_wo_permission) do
@@ -64,16 +64,16 @@ MESSAGE
FactoryBot.create(:user)
else
FactoryBot.create(:user,
- member_in_project: project,
- member_through_role: non_watcher_role)
+ member_in_project: project,
+ member_through_role: non_watcher_role)
end
end
let(:admin) { FactoryBot.build(:admin) }
let(:anonymous_user) { FactoryBot.build(:anonymous) }
let(:watching_user) do
FactoryBot.create(:user,
- member_in_project: project,
- member_through_role: watcher_role).tap do |user|
+ member_in_project: project,
+ member_through_role: watcher_role).tap do |user|
Watcher.create(watchable: model_instance, user: user)
end
end
diff --git a/spec_legacy/unit/user_spec.rb b/spec_legacy/unit/user_spec.rb
index 7f0542e721d..33b4563fb99 100644
--- a/spec_legacy/unit/user_spec.rb
+++ b/spec_legacy/unit/user_spec.rb
@@ -189,7 +189,7 @@ describe User, type: :model do
user = User.try_to_login('jsmith', 'jsmith')
assert_equal @jsmith, user
- @jsmith.status = User::STATUSES[:locked]
+ @jsmith.status = User.statuses[:locked]
assert @jsmith.save
user = User.try_to_login('jsmith', 'jsmith')
@@ -285,7 +285,7 @@ describe User, type: :model do
end
it 'should return nil if the key is found for an inactive user' do
- user = FactoryBot.create(:user, status: User::STATUSES[:locked])
+ user = FactoryBot.create(:user, status: User.statuses[:locked])
token = FactoryBot.build(:api_token, user: user)
user.api_token = token
user.save
@@ -294,7 +294,7 @@ describe User, type: :model do
end
it 'should return the user if the key is found for an active user' do
- user = FactoryBot.create(:user, status: User::STATUSES[:active])
+ user = FactoryBot.create(:user, status: User.statuses[:active])
token = FactoryBot.build(:api_token, user: user)
user.api_token = token
user.save