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

FileLinks: Added comments for Rooky Devs and fixed RuboCop complaints (#10183)

Frank Bergmann3b67b8106b34
diff --git a/modules/storages/app/cells/storages/projects_storages_row_cell.rb b/modules/storages/app/cells/storages/projects_storages_row_cell.rb
index 070071cb7d5..dd18dd0ca99 100644
--- a/modules/storages/app/cells/storages/projects_storages_row_cell.rb
+++ b/modules/storages/app/cells/storages/projects_storages_row_cell.rb
@@ -1,3 +1,8 @@
+# Purpose: Defines how to format the cells within a table of ProjectStorages
+# associated with a project
+# Used by: projects_storages_table_cell.rb - the methods defined here
+# correspond to the columns value in the table model.
+# See for more comments: storage_row_cell.rb
module Storages
class ProjectsStoragesRowCell < ::RowCell
include ::IconsHelper
diff --git a/modules/storages/app/cells/storages/projects_storages_table_cell.rb b/modules/storages/app/cells/storages/projects_storages_table_cell.rb
index 50d144de15c..81424f76373 100644
--- a/modules/storages/app/cells/storages/projects_storages_table_cell.rb
+++ b/modules/storages/app/cells/storages/projects_storages_table_cell.rb
@@ -26,6 +26,12 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# Purpose: Defines a table based on RubyCell for listing the
+# Storages::ProjectStorage per project in the projects' settings
+# page.
+# See for comments: storage_table_cell.rb
+# See also: project_storages_row_cell.rb, which contains a method
+# for every "column" defined below.
module Storages
class ProjectsStoragesTableCell < ::TableCell
include ::IconsHelper
@@ -60,10 +66,10 @@ module Storages
def headers
[
- ['name', { caption: ::Storages::Storage.human_attribute_name(:name) }],
+ ['name', { caption: Storages::Storage.human_attribute_name(:name) }],
['provider_type', { caption: I18n.t('storages.provider_types.label') }],
['creator', { caption: I18n.t('storages.label_creator') }],
- ['created_at', { caption: ::Storages::ProjectStorage.human_attribute_name(:created_at) }]
+ ['created_at', { caption: Storages::ProjectStorage.human_attribute_name(:created_at) }]
]
end
end
diff --git a/modules/storages/app/cells/storages/storages_row_cell.rb b/modules/storages/app/cells/storages/storages_row_cell.rb
index 4a8188273ed..493a9fe5bf6 100644
--- a/modules/storages/app/cells/storages/storages_row_cell.rb
+++ b/modules/storages/app/cells/storages/storages_row_cell.rb
@@ -1,13 +1,18 @@
+# Purpose: Defines the row model for the table of Storage objects
+# Used by: Storage table in storages_table_cell.rb
+# Reference: RubyCells???
module Storages
class StoragesRowCell < ::RowCell
- include ::IconsHelper
- include ::AvatarHelper
- include ::Redmine::I18n
+ include ::IconsHelper # Global helper for icons, defines op_icon and icon_wrapper?
+ include ::AvatarHelper # Global helper for avatar (image of a user)
+ include ::Redmine::I18n # Internationalization support (defines I18n.t(...) translation)
def name
link_to model.name, storage_path(model)
end
+ # Delegate delegates the execution of certain methods to :model.
+ # ToDo: I'm not sure why this makes sense here.
delegate :host, to: :model
delegate :provider_type, to: :model
diff --git a/modules/storages/app/cells/storages/storages_table_cell.rb b/modules/storages/app/cells/storages/storages_table_cell.rb
index e640424c765..c846d9b86d8 100644
--- a/modules/storages/app/cells/storages/storages_table_cell.rb
+++ b/modules/storages/app/cells/storages/storages_table_cell.rb
@@ -1,23 +1,37 @@
+# Purpose: Defines a table with the list of Storages::Storage
+# objects in the global admin section of OpenProject
+# Used by: the admin list of all storages in the system
+# (storages/app/views/storages/admin/index.html.erb)
+# Reference: RailsCells???, ToDo: no documentation found
+# See also: storage_row_cell.rb with the row model of the table
module Storages
class StoragesTableCell < ::TableCell
- include ::IconsHelper
+ include ::IconsHelper # Global helper for icons, defines op_icon(...)
+ # ???
class << self
def row_class
::Storages::StoragesRowCell
end
end
+ # Defines the list of columns in the table using symbols.
+ # These symbols are used below to define header (top of the table)
+ # and contents of the cells
columns :name, :provider_type, :host, :creator, :created_at
+ # Default sort order (overwritten by user)
def initial_sort
%i[created_at asc]
end
+ # Should RubyCell show ^/v icons in the header to allow custom sorting?
def sortable?
false
end
+ # Used by: ???
+ # Purpose: ???
def inline_create_link
link_to(new_storage_path,
class: 'wp-inline-create--add-link',
@@ -26,10 +40,12 @@ module Storages
end
end
+ # Show this pretty message if there are now Storages::Storage objects in the system
def empty_row_message
I18n.t 'storages.no_results'
end
+ # Definition of the table header using the keys from columns above.
def headers
[
['name', { caption: ::Storages::Storage.human_attribute_name(:name) }],
diff --git a/modules/storages/app/contracts/storages/file_links/delete_contract.rb b/modules/storages/app/contracts/storages/file_links/delete_contract.rb
index bcebe5af9d2..d0a97558c63 100644
--- a/modules/storages/app/contracts/storages/file_links/delete_contract.rb
+++ b/modules/storages/app/contracts/storages/file_links/delete_contract.rb
@@ -26,17 +26,24 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# ToDo: Why is there only one contract for FileLinks?
+# Used by: ???
+# Why here two module blocks instead of Storages::FileLinks?
module Storages
module FileLinks
class DeleteContract < ::ModelContract
+ # ToDo: What is this? Where is this used?
def self.model
Storages::FileLink
end
+ # Check permissions to delete(?) this FileLink
validate :validate_manage_allowed
+ # The permission check below doesn't need to be visible in other parts.
private
+ # Just check the global permissions system
def validate_manage_allowed
unless user.allowed_to?(:manage_file_links, model.container.project)
errors.add :base, :error_unauthorized
diff --git a/modules/storages/app/contracts/storages/storages/concerns/manage_storages_guarded.rb b/modules/storages/app/contracts/storages/storages/concerns/manage_storages_guarded.rb
index 614f4fb1860..a1166c3043d 100644
--- a/modules/storages/app/contracts/storages/storages/concerns/manage_storages_guarded.rb
+++ b/modules/storages/app/contracts/storages/storages/concerns/manage_storages_guarded.rb
@@ -28,16 +28,33 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# Purpose: This is a "concern" to check if a user is authorized to
+# Manage Storages. ToDo: Why "Guarded"?
+# It acts as a factored-out add-on to a model, that's why there is
+# model specific functions in the "included" callback.
+# Reference: Here is a tutorial about concerns. They basically inject
+# the content of the "included do ... end" block into their target.
+# http://vaidehijoshi.github.io/blog/2015/10/13/stop-worrying-and-start-being-concerned-activesupport-concerns/
+# Used by: ToDo: Check usage.
+# ToDo: Why is this in a different from before_xxx authenticate?
+# ToDo: Is this really used multiple times?
+# Returns: An array of errors with section and code
module Storages::Storages
module Concerns
module ManageStoragesGuarded
+ # extend is like include, but imports methods as class (not instance) methods.
+ # Using extend ActiveSupport::Concern is part of the Concern pattern.
extend ActiveSupport::Concern
+ # "included" is a callback that is invoked whenever this Concern is
+ # included in another module or class, injecting the contents of the do-end block
included do
+ # Generic validation to call a custom procedure in a Rails
validate :validate_user_allowed_to_manage
private
+ # Small procedure to check that the current user is (global?)admin and active
def validate_user_allowed_to_manage
unless user.admin? && user.active?
errors.add :base, :error_unauthorized
diff --git a/modules/storages/app/contracts/storages/storages/create_contract.rb b/modules/storages/app/contracts/storages/storages/create_contract.rb
index d70c6c9c335..eba5597d25a 100644
--- a/modules/storages/app/contracts/storages/storages/create_contract.rb
+++ b/modules/storages/app/contracts/storages/storages/create_contract.rb
@@ -1,6 +1,6 @@
#-- copyright
# OpenProject is an open source project management software.
-# Copyright (C) 2012-2021 the OpenProject GmbH
+# Copyright (C) 2012-2022 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.
@@ -26,6 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: base_contract.rb for comments
module Storages::Storages
# We create the empty class here, so that other pieces of code that looks for the contract in its default place will
# find it. So, the CreateService for Storages will expect its contract to be here.
diff --git a/modules/storages/app/contracts/storages/storages/delete_contract.rb b/modules/storages/app/contracts/storages/storages/delete_contract.rb
index e54611a7690..71e18a770e3 100644
--- a/modules/storages/app/contracts/storages/storages/delete_contract.rb
+++ b/modules/storages/app/contracts/storages/storages/delete_contract.rb
@@ -26,6 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: base_contract.rb for comments
module Storages
module Storages
class DeleteContract < ::DeleteContract
diff --git a/modules/storages/app/contracts/storages/storages/update_contract.rb b/modules/storages/app/contracts/storages/storages/update_contract.rb
index d24df162990..c2ce143caae 100644
--- a/modules/storages/app/contracts/storages/storages/update_contract.rb
+++ b/modules/storages/app/contracts/storages/storages/update_contract.rb
@@ -29,6 +29,7 @@
require 'net/http'
require 'uri'
+# See also: base_contract.rb for comments
module Storages::Storages
class UpdateContract < ::Storages::Storages::BaseContract
end
diff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb
index 566252ba555..99722a0eda0 100644
--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb
@@ -28,6 +28,9 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# Purpose: Controls the page that enables/disables Storages per project.
+# See also: storages_controller.rb for a controller with very similar structure.
+# ToDo: Some differences to StoragesController?
class Storages::Admin::ProjectsStoragesController < Projects::SettingsController
model_object Storages::ProjectStorage
diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb
index 32dc4beadc0..045cd894426 100644
--- a/modules/storages/app/controllers/storages/admin/storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb
@@ -28,37 +28,78 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# Purpose: CRUD the global admin page of Storages (=Nextcloud servers)
+# ToDo: Why not use double "module"
+# ToDo: What Wieland already explained ::Module vs. Module (without ::)
class Storages::Admin::StoragesController < ApplicationController
+ # ToDo: Where is this used?
+ # I assume this will create a page layout for a global OpenProject admin page
layout 'admin'
+ # I assume this is necessary because of the non-standard path of this controller?
model_object Storages::Storage
+ # Before executing any action below: Make sure the current user is an admin
+ # and set the @<controller_name> variable to the object refernced in the URL.???
before_action :require_admin
before_action :find_model_object, only: %i[show destroy edit update]
+ # ToDo: Where is this used?
+ # I understand this will create(???) a menu item in Admin to Storages
menu_item :storages_admin_settings
+ # Index page with a list of Storages objects
+ # Called by: Global app/config/routes.rb to serve Web page
def index
@storages = Storages::Storage.all
+ # The view is located in a slightly off-standard directory
+ # Why not use a leading "/" as in other places?
render 'storages/admin/index'
end
+ # Show page with details of one Storage object.
+ # Called by: Global app/config/routes.rb to serve Web page
def show
render 'storages/admin/show'
end
+ # Show the admin page to create a new Storage object.
+ # Sets the attributes provider_type and name for the service(???)
+ # as default values and then renders the new page (allowing the user
+ # to overwrite these values and to fill in other attributes).
+ # Used by: The index page above, when the user presses the (+) button.
+ # Called by: Global app/config/routes.rb to serve Web page
def new
+ # Set default parameters using a "service".
+ # See also: storages/services/storages/storages/set_attributes_services.rb
+ # See also: ToDo: Service documentation from Wieland
+ # That service inherits from ::BaseServices::SetAttributes
+ # ToDo: I don't understand where call(...) is defined, and what this
+ # service actually does.
@object = ::Storages::Storages::SetAttributesService
.new(user: current_user,
model: Storages::Storage.new,
contract_class: EmptyContract)
.call({ provider_type: 'nextcloud', name: I18n.t('storages.provider_types.nextcloud') })
.result
+ # What about error processing in case the service returns nil???
+ # Render the new page in a slightly off-standard location
render 'storages/admin/new'
end
+ # ToDo: RuboCop: Metrics/AbcSize: Assignment Branch Condition size for create is too high. [<7, 21, 2> 22.23/17]
+ # ToDo: Move the comments back into the method
+ # Actually create a Storage object.
+ # Overwrite the creator_id with the current_user. Is this this pattern always used?
+ # Use service pattern to create a new Storage
+ # See also: storages/services/storages/storages/create_service.rb
+ # storage_path is automagically created by Ruby controller for the Storage object.
+ # Just render a response to (un-)successful creation.
+ # respond_to takes a URL parameter about the format. Only HTML is supported here.
+ # Called by: Global app/config/routes.rb to serve Web page
+ # rubocop:disable Metrics/AbcSize
def create
combined_params = permitted_storage_params.to_h.reverse_merge(creator_id: current_user.id)
service_result = Storages::Storages::CreateService.new(user: current_user).call(combined_params)
@@ -80,12 +121,20 @@ class Storages::Admin::StoragesController < ApplicationController
end
end
end
+ # rubocop:enable Metrics/AbcSize
+ # Edit page is very similar to new page, except that we don't need to set
+ # default attribute values because the object already exists
+ # Called by: Global app/config/routes.rb to serve Web page
def edit
render 'storages/admin/edit'
end
+ # Update is similar to create above
+ # Also see: create above
+ # Called by: Global app/config/routes.rb to serve Web page
def update
+ # ToDo: Multi-line call to service instead of one-line above
service_result = ::Storages::Storages::UpdateService
.new(user: current_user,
model: @object)
@@ -107,13 +156,18 @@ class Storages::Admin::StoragesController < ApplicationController
end
end
+ # Purpose: Destroy a specific Storage
+ # Called by: Global app/config/routes.rb to serve Web page
def destroy
Storages::Storages::DeleteService
.new(user: User.current, model: @object)
.call
+ # ToDo: Where is "flash" defined
+ # Displays a message box on the next page
flash[:info] = I18n.t(:notice_successful_delete)
+ # Redirect to the index page
respond_to do |format|
format.html do
redirect_to storages_path
@@ -121,6 +175,9 @@ class Storages::Admin::StoragesController < ApplicationController
end
end
+ # Used by: ToDo:
+ # Breadcrumbs is something like OpenProject > Admin > Storages.
+ # This returns the name of the last part (Storages admin page)
def default_breadcrumb
if action_name == :index
t(:project_module_storages)
@@ -129,13 +186,18 @@ class Storages::Admin::StoragesController < ApplicationController
end
end
+ # See: default_breadcrum above
+ # Defines whether to show breadcrumbs on the page or not.
def show_local_breadcrumb
true
end
private
+ # Called by create and update above in order to check if the
+ # update parameters are correctly set.
def permitted_storage_params
+ # ToDo: How does :storages_storage work? Isn't this "id"? Who transforms?
params
.require(:storages_storage)
.permit('name', 'provider_type', 'host')
diff --git a/modules/storages/app/models/queries/storages/file_links/file_link_query.rb b/modules/storages/app/models/queries/storages/file_links/file_link_query.rb
index 763f292693b..82ae4ef00de 100644
--- a/modules/storages/app/models/queries/storages/file_links/file_link_query.rb
+++ b/modules/storages/app/models/queries/storages/file_links/file_link_query.rb
@@ -1,6 +1,16 @@
+# ToDo: Copyright notice missing
+# Purpose: ???
+# Used by: ???
+# Reference: ToDo: Link to documentation about queries
+
+# Why is there a Queries::Storages namespace?
class Queries::Storages::FileLinks::FileLinkQuery < Queries::BaseQuery
+ # What is class << self?
class << self
+ # Why model?
def model
+ # Where is the model needed? From where is it called?
+ # ToDo: What is constantize?
@model ||= '::Storages::FileLink'.constantize
end
end
diff --git a/modules/storages/app/models/storages/file_link.rb b/modules/storages/app/models/storages/file_link.rb
index aea9202fc4a..33bb7e13155 100644
--- a/modules/storages/app/models/storages/file_link.rb
+++ b/modules/storages/app/models/storages/file_link.rb
@@ -26,11 +26,31 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# A FileLink represents a single file stored in some Storage
+# (currently basically a Nextcloud store). Additional attributes
+# and constraints are defined in db/migrate/20220113144759_create_file_links.rb
+# FileLinks are attached to a "container", which currently has to
+# be a WorkPackage.
+#
+# Purpose: The code below is a standard Ruby model:
+# https://guides.rubyonrails.org/active_model_basics.html
+# It defines defines checks and permissions on the Ruby level.
+# Additional attributes and constraints are defined in
+# db/migrate/20220113144759_create_file_links.rb migration.
class Storages::FileLink < ApplicationRecord
+ # Every FileLink references it's Storage. A "on delete cascade"
+ # is defined in the migration, so this FileLink will be deleted
+ # when deleting the Storage.
belongs_to :storage
belongs_to :creator, class_name: 'User'
- belongs_to :container, class_name: 'WorkPackage' # This needs to become more flexible in the future
+ # FileLinks are attached to a container ()currently a WorkPackage)
+ # Wieland: This needs to become more flexible in the future
+ belongs_to :container, class_name: 'WorkPackage'
+ # A standard Rails custom query:
+ # https://www.rubyguides.com/2019/10/scopes-in-ruby-on-rails/
+ # Purpose: ToDo: not clear what this condition means
+ # Used by: ToDo:
scope :visible, ->(user = User.current) {
includes(:container)
.includes(container: :project)
diff --git a/modules/storages/app/models/storages/project_storage.rb b/modules/storages/app/models/storages/project_storage.rb
index 2d32d410db9..387c74baaab 100644
--- a/modules/storages/app/models/storages/project_storage.rb
+++ b/modules/storages/app/models/storages/project_storage.rb
@@ -28,11 +28,37 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# A ProjectStorage is a kind of relation between a Storage and
+# a Project in order to enable or disable a Storage for a specific
+# WorkPackages in the project.
+# See also: file_link.rb and storage.rb
class Storages::ProjectStorage < ApplicationRecord
+ # ToDo: Why is this necessary? Because otherwise it would be project_storages?
self.table_name = 'projects_storages'
+
+ # ProjectStorage sits between Project and Storage.
belongs_to :project
belongs_to :storage, class_name: 'Storages::Storage'
belongs_to :creator, class_name: 'User'
+ # There should be only one ProjectStorage per project and storage.
validates :project, uniqueness: { scope: :storage }
+
+ # Use a callback to delete dependent FileLinks.
+ before_destroy :delete_associated_file_links
+
+ private
+
+ # Delete FileLinks with the same Storage as the ProjectStorage.
+ # Also, they are attached to WorkPackages via the Project.
+ def delete_associated_file_links
+ # work_packages is an ActiveRecord::Relation, not an array of objects!
+ work_packages = WorkPackage.where(project_id: project_id)
+ file_links = Storages::FileLink.where(storage_id: storage_id, container: work_packages)
+ # use file_links.to_sql to check the SQL generated by the lines above.
+ # It uses a fast SQL "container_id in (select * from work_packages...)", so the
+ # delete_all below is executed using a single query.
+ # Reference: https://api.rubyonrails.org/classes/ActiveRecord/Relation.html
+ file_links.delete_all
+ end
end
diff --git a/modules/storages/app/models/storages/storage.rb b/modules/storages/app/models/storages/storage.rb
index 84a5d56fc36..4b2b13ac167 100644
--- a/modules/storages/app/models/storages/storage.rb
+++ b/modules/storages/app/models/storages/storage.rb
@@ -26,12 +26,27 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# A "Storage" refers to some external source where files are stored.
+# The first supported storage is Nextcloud (www.nextcloud.com).
+# a Storage is mainly defined by a name, a "provider_type" (i.e.
+# Nextcloud or something similar) and a "host" URL.
+#
+# Purpose: The code below is a standard Ruby model:
+# https://guides.rubyonrails.org/active_model_basics.html
+# It defines defines checks and permissions on the Ruby level.
+# Additional attributes and constraints are defined in
+# db/migrate/20220113144323_create_storage.rb "migration".
class Storages::Storage < ApplicationRecord
+ # One Storage can have multiple FileLinks, representing external files
has_many :file_links, class_name: 'Storages::FileLink'
+ # Basically every OpenProject object has a creator
belongs_to :creator, class_name: 'User'
+ # A project manager can enable/disable Storages per project.
has_many :projects_storages, dependent: :destroy, class_name: 'Storages::ProjectStorage'
+ # We can get the list of projects with this Storage enabled.
has_many :projects, through: :projects_storages
+ # Uniqueness - no two storages should have the same host.
validates_uniqueness_of :host
validates_uniqueness_of :name
diff --git a/modules/storages/app/services/storages/file_links/delete_service.rb b/modules/storages/app/services/storages/file_links/delete_service.rb
index 92be0972e14..3973f44cdca 100644
--- a/modules/storages/app/services/storages/file_links/delete_service.rb
+++ b/modules/storages/app/services/storages/file_links/delete_service.rb
@@ -26,6 +26,8 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: ../storages/create_service.rb for comments
+# ToDo: There are two module statements here instead of one in storages/create_service.rb
module Storages
module FileLinks
class DeleteService < ::BaseServices::Delete
diff --git a/modules/storages/app/services/storages/storages/create_service.rb b/modules/storages/app/services/storages/storages/create_service.rb
index 1b40ba909b4..cece362161c 100644
--- a/modules/storages/app/services/storages/storages/create_service.rb
+++ b/modules/storages/app/services/storages/storages/create_service.rb
@@ -26,6 +26,13 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# The comments here are also referenced from the other *_service.rb files in the module
+# ToDo: add purpose
+# ToDo: Where is the model called? I believe this one isn't called at all, right?
+# ToDo: Why Storages::Storage_s_ module?
+# File Links uses two modules lines in:
+# modules/storages/app/services/storages/file_links/delete_service.rb
+# Reference: ToDo: Link to documentation on services
module Storages::Storages
class CreateService < ::BaseServices::Create
end
diff --git a/modules/storages/app/services/storages/storages/delete_service.rb b/modules/storages/app/services/storages/storages/delete_service.rb
index 197fb733d49..ca5347e59a7 100644
--- a/modules/storages/app/services/storages/storages/delete_service.rb
+++ b/modules/storages/app/services/storages/storages/delete_service.rb
@@ -28,6 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: create_service.rb for comments
module Storages::Storages
class DeleteService < ::BaseServices::Delete
end
diff --git a/modules/storages/app/services/storages/storages/set_attributes_service.rb b/modules/storages/app/services/storages/storages/set_attributes_service.rb
index 6739655112f..5912cdb1a77 100644
--- a/modules/storages/app/services/storages/storages/set_attributes_service.rb
+++ b/modules/storages/app/services/storages/storages/set_attributes_service.rb
@@ -26,6 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: create_service.rb for comments
module Storages::Storages
class SetAttributesService < ::BaseServices::SetAttributes
end
diff --git a/modules/storages/app/services/storages/storages/update_service.rb b/modules/storages/app/services/storages/storages/update_service.rb
index 2770466c2df..a055d19abdd 100644
--- a/modules/storages/app/services/storages/storages/update_service.rb
+++ b/modules/storages/app/services/storages/storages/update_service.rb
@@ -26,6 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: create_service.rb for comments
module Storages::Storages
class UpdateService < ::BaseServices::Update
end
diff --git a/modules/storages/app/views/storages/admin/_form.html.erb b/modules/storages/app/views/storages/admin/_form.html.erb
index d3d3f9db1fe..6afbba15ec5 100644
--- a/modules/storages/app/views/storages/admin/_form.html.erb
+++ b/modules/storages/app/views/storages/admin/_form.html.erb
@@ -27,6 +27,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
+<!-- Included form for create and edit operations, please see the controller for comments -->
<%= error_messages_for_contract @object, @errors %>
<section class="form--section">
diff --git a/modules/storages/app/views/storages/admin/edit.html.erb b/modules/storages/app/views/storages/admin/edit.html.erb
index 303492a0824..e76e31f05a5 100644
--- a/modules/storages/app/views/storages/admin/edit.html.erb
+++ b/modules/storages/app/views/storages/admin/edit.html.erb
@@ -1,3 +1,4 @@
+<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t("project_module_storages"), t('label_edit_x', x: @object.name) %>
<% local_assigns[:additional_breadcrumb] = @object.name %>
<%= toolbar title: t('label_edit_x', x: @object.name) %>
diff --git a/modules/storages/app/views/storages/admin/index.html.erb b/modules/storages/app/views/storages/admin/index.html.erb
index a1f7d51a423..f836df632cb 100644
--- a/modules/storages/app/views/storages/admin/index.html.erb
+++ b/modules/storages/app/views/storages/admin/index.html.erb
@@ -1,3 +1,4 @@
+<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t("project_module_storages") %>
<%= toolbar title: t("project_module_storages") do %>
diff --git a/modules/storages/app/views/storages/admin/new.html.erb b/modules/storages/app/views/storages/admin/new.html.erb
index 3754527376a..614c60945e5 100644
--- a/modules/storages/app/views/storages/admin/new.html.erb
+++ b/modules/storages/app/views/storages/admin/new.html.erb
@@ -1,3 +1,4 @@
+<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t("project_module_storages"), t('storages.label_new_storage') %>
<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %>
<%= toolbar title: t("storages.label_new_storage") %>
diff --git a/modules/storages/app/views/storages/admin/show.html.erb b/modules/storages/app/views/storages/admin/show.html.erb
index f3889c8eda2..1c849d53c80 100644
--- a/modules/storages/app/views/storages/admin/show.html.erb
+++ b/modules/storages/app/views/storages/admin/show.html.erb
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
+<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t('project_module_storages'), t(@object.name) -%>
<% local_assigns[:additional_breadcrumb] = @object.name %>
diff --git a/modules/storages/app/views/storages/project_settings/_toast_no_storage_set_up.html.erb b/modules/storages/app/views/storages/project_settings/_toast_no_storage_set_up.html.erb
index 23d2856b152..1d3c460a1c2 100644
--- a/modules/storages/app/views/storages/project_settings/_toast_no_storage_set_up.html.erb
+++ b/modules/storages/app/views/storages/project_settings/_toast_no_storage_set_up.html.erb
@@ -1,3 +1,4 @@
+<!-- Standard Ruby view, please see the controller for comments -->
<div class="op-toast -info">
<div class="op-toast--content">
<p>
diff --git a/modules/storages/app/views/storages/project_settings/index.html.erb b/modules/storages/app/views/storages/project_settings/index.html.erb
index 7878c10dd33..7892d0aabe3 100644
--- a/modules/storages/app/views/storages/project_settings/index.html.erb
+++ b/modules/storages/app/views/storages/project_settings/index.html.erb
@@ -1,3 +1,4 @@
+<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t("project_module_storages") %>
<% if ::Storages::Storage.any? %>
diff --git a/modules/storages/app/views/storages/project_settings/new.html.erb b/modules/storages/app/views/storages/project_settings/new.html.erb
index ca1ff1e6d29..1f67552a5fc 100644
--- a/modules/storages/app/views/storages/project_settings/new.html.erb
+++ b/modules/storages/app/views/storages/project_settings/new.html.erb
@@ -1,3 +1,4 @@
+<!-- Standard Ruby view, please see the controller for comments -->
<% html_title t(:label_administration), t("project_module_storages") %>
<% local_assigns[:additional_breadcrumb] = t('storages.label_new_storage') %>
<%= toolbar title: t("storages.page_titles.project_settings.new") %>
diff --git a/modules/storages/lib/api/v3/file_links/file_links_api.rb b/modules/storages/lib/api/v3/file_links/file_links_api.rb
index 13cb8a895da..a441ba928ff 100644
--- a/modules/storages/lib/api/v3/file_links/file_links_api.rb
+++ b/modules/storages/lib/api/v3/file_links/file_links_api.rb
@@ -26,10 +26,14 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: ../storages_api.rb for comments
+# ToDo: I've checked the other files and didn't understand anything...
module API
module V3
module FileLinks
class FileLinksAPI < ::API::OpenProjectAPI
+ # Helpers are defined here: https://github.com/ruby-grape/grape#helpers
+ # ToDo: However, I didn't really understand what this thing does and where it's called
helpers do
def visible_file_links_scope
::Storages::FileLink.visible(current_user)
diff --git a/modules/storages/lib/api/v3/storages/storage_representer.rb b/modules/storages/lib/api/v3/storages/storage_representer.rb
index b90229394c7..8535c488fca 100644
--- a/modules/storages/lib/api/v3/storages/storage_representer.rb
+++ b/modules/storages/lib/api/v3/storages/storage_representer.rb
@@ -26,13 +26,22 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# I understand this is a Roar "representer":
+# Also see: For Roar documentation https://github.com/trailblazer/roar
+# and the Roar-Rails integration: https://github.com/apotonick/roar-rails
+# Roar is a "thin layer on top of": https://github.com/trailblazer/representable
+# "Representable maps Ruby objects to documents and back"
+# ToDo: What exactly is a representer? I understand it's atrributes plus
+# a number of links? These are the ones defined below?
module API
module V3
module Storages
class StorageRepresenter < ::API::Decorators::Single
+ # ToDo: LinkedResource is about linking to other objects related to Storages?
include API::Decorators::LinkedResource
include API::Decorators::DateProperty
+ # ToDo: repeating again the attributes of a Storage?
property :id
property :name
@@ -41,6 +50,8 @@ module API
date_time_property :updated_at
+ # A link back to the specific object ("represented"):
+ # ToDo: what is "storage(...)" here?
link :self do
{
href: api_v3_paths.storage(represented.id),
@@ -48,6 +59,8 @@ module API
}
end
+ # There is apparently just a single type supported at the moment...
+ # ToDo: So this URL is fake?
link :type do
{
href: "#{::API::V3::URN_PREFIX}storages:nextcloud",
diff --git a/modules/storages/lib/api/v3/storages/storages_api.rb b/modules/storages/lib/api/v3/storages/storages_api.rb
index d65a0a18753..3d23844dcb8 100644
--- a/modules/storages/lib/api/v3/storages/storages_api.rb
+++ b/modules/storages/lib/api/v3/storages/storages_api.rb
@@ -26,9 +26,15 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# In understand this file sets up routing for the Storages API based on
+# the Grape REST API Framework.
+# ToDo: I understand the naming of this file follows the API::V::Storages::StoragesAPI module
+# names, just that this starts in storages/lib/?
+# Is it Grape that somehow knows how to load this file? What is the Grape load order?
module API
module V3
module Storages
+ # OpenProjectAPI is a simple subclass of Grape::API that handles patches.
class StoragesAPI < ::API::OpenProjectAPI
helpers do
def visible_storages_scope
@@ -36,12 +42,22 @@ module API
end
end
+ # ToDo: The "resources" keyword is from config/routes.rb.
+ # What does "resources" mean in the context of Grape? Just like in routes.rb?
resources :storages do
+ # Didn't understand route_param in Grape...
route_param :storage_id, type: Integer, desc: 'Storage id' do
+ # Execute the do...end lines after parameter validation but before the actual
+ # call to the API method.
+ # Please see: The after_validation call-back in Grape:
+ # https://github.com/ruby-grape/grape#before-after-and-finally
after_validation do
@storage = visible_storages_scope.find(params[:storage_id])
end
+ # I understand that the line below defined a reaction to a GET request...
+ # ToDo: What is this ampersand "&" before the ::API?
+ # ToDo: Any documentation on API endpoints?
get &::API::V3::Utilities::Endpoints::Show.new(model: ::Storages::Storage).mount
end
end
diff --git a/modules/storages/lib/open_project/storages.rb b/modules/storages/lib/open_project/storages.rb
index 7ddc63563e2..7fedc5ea233 100644
--- a/modules/storages/lib/open_project/storages.rb
+++ b/modules/storages/lib/open_project/storages.rb
@@ -26,6 +26,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# ToDo: Why is the require wrapped in two modules and not at the beginning?
+# Does it work like an include?
+# ToDo: I understand this is part of the Engine definition, which has to reside
+# here in the storages/lib folder?
module OpenProject
module Storages
require 'open_project/storages/engine'
diff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rb
index ae9c122d781..994a1540019 100644
--- a/modules/storages/lib/open_project/storages/engine.rb
+++ b/modules/storages/lib/open_project/storages/engine.rb
@@ -26,17 +26,29 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# See also: Getting started with Engines: https://guides.rubyonrails.org/engines.html
+# ToDo: What is the name convention for where to store the engine.rb file? Why is
+# there an open_project in the path?
module OpenProject::Storages
class Engine < ::Rails::Engine
+ # ToDo: Where is this used/referenced?
engine_name :openproject_storages
+ # ToDo: I understand these are OP specific helpers, but which ones are used?
+ # The next line "register" is defined here as well as "add_api_path" etc.
+ # ToDo: But why is this included and not referenced?
include OpenProject::Plugins::ActsAsOpEngine
+ # For documentation see the definition of register in "ActsAsOpEngine"
+ # This corresponds to the openproject-storage.gemspec
+ # Pass a block to the plugin (for defining permissions, menu items and the like)
register 'openproject-storages',
author_url: 'https://www.openproject.org',
bundled: true,
settings: {},
name: 'OpenProject Storages' do
+ # ToDo: Redmine plugin API?
+ # Apparently only defined the name, dependencies and global(?) permissions?
project_module :storages, dependencies: :work_package_tracking do
permission :view_file_links,
{},
@@ -50,6 +62,8 @@ module OpenProject::Storages
end
# Menu extensions
+ # Add a "storages_admin_settings" to the admin_menu with the specified link,
+ # condition ("if:"), caption and icon.
menu :admin_menu,
:storages_admin_settings,
{ controller: '/storages/admin/storages', action: :index },
@@ -64,6 +78,7 @@ module OpenProject::Storages
parent: :settings
end
+ # ToDo: Why is there |storage_id|? Is this a kind of manual routes.rb?
add_api_path :storage do |storage_id|
"#{root}/storages/#{storage_id}"
end
diff --git a/modules/storages/lib/openproject-storages.rb b/modules/storages/lib/openproject-storages.rb
index 8c1dd3f9db1..0b51a86fa14 100644
--- a/modules/storages/lib/openproject-storages.rb
+++ b/modules/storages/lib/openproject-storages.rb
@@ -1 +1,6 @@
+# ToDo: Whiy is this file necessary? Where is documentation about the RoR loader? Zeitwerk?
+# This standard guide explains Zeitwerk, but does not explain the "require" below.
+# https://guides.rubyonrails.org/autoloading_and_reloading_constants.html
+# ToDo: Also: Why is this file called openproject-storages.rb? Where is this convention explained?
+# This doesn't seem to follow Zeitwerk conventions.
require 'open_project/storages'
diff --git a/modules/storages/openproject-storages.gemspec b/modules/storages/openproject-storages.gemspec
index 13cf6236263..75795cab164 100644
--- a/modules/storages/openproject-storages.gemspec
+++ b/modules/storages/openproject-storages.gemspec
@@ -1,5 +1,41 @@
-# encoding: UTF-8
-
+# This is the first file in the storages plugin, so I'll use # it to
+# include some general comments (ToDo: Move this into a separate
+# file?).
+# With the comments in this file we try to lift you from a beginner's
+# level to an intermediary level of Ruby on Rails in the context of
+# OpenProject.
+# After reviewing this plugin, you will probably be able to create new
+# plugins yourself and to perform small to medium extensions of OpenProject.
+# Preconditions:
+# - We assume that you are more or less familiar with the Ruby
+# language. If not, please check: ToDo: Ruby tutorial
+# - We also assume that you are familiar with the basic Rails concepts
+# and that you have built the usual toy application (blog with
+# posts) yourself. So you know what is a model, a controller, a view,
+# a database migration etc.
+# - Just go to https://guides.rubyonrails.org/
+# and read and practice most of the guides, except for the last sections
+# on Extending Rails, Contributions, Policies and Release Notes.
+# - Frank Bergmann has put together some tips and tricks on how to setup
+# a development environment and to get started developing:
+# ToDo: Publish PPTs
+#
+# ToDo: Copy /db/ and migrations from the global application to a local
+# ./db/ folder?
+#
+# Other good resources:
+# - Modules vs. Classes:
+# https://medium.com/rubycademy/modules-in-ruby-part-i-a2cdfaccdb6e and
+# Explains the concepts of module (vs. class) and mixing, together with
+# the keywords module, include, prepend and extend.
+# - Mixins and Modules:
+# https://blog.appsignal.com/2021/01/13/using-mixins-and-modules-in-your-ruby-on-rails-application.html
+#
+#
+# Used by: OpenProject package manager(?)
+# Purpose: Defines the metadata for the module
+# References: https://guides.rubygems.org/specification-reference/
+# rubocop:disable Gemspec/RequireMFA
Gem::Specification.new do |s|
s.name = 'openproject-storages'
s.version = '1.0.0'
@@ -8,6 +44,6 @@ Gem::Specification.new do |s|
s.summary = 'OpenProject Storages'
s.description = 'Allows linking work packages to files in external storages, such as Nextcloud.'
s.license = 'GPLv3'
-
s.files = Dir['{app,config,db,lib}/**/*']
end
+# rubocop:enable Gemspec/RequireMFA
diff --git a/modules/storages/spec/contracts/views/create_contract_file_link_spec.rb b/modules/storages/spec/contracts/views/create_contract_file_link_spec.rb
index 34dba0586de..cf0894646ab 100644
--- a/modules/storages/spec/contracts/views/create_contract_file_link_spec.rb
+++ b/modules/storages/spec/contracts/views/create_contract_file_link_spec.rb
@@ -30,6 +30,8 @@ require 'spec_helper'
require 'contracts/shared/model_contract_shared_context'
require 'contracts/views/shared_contract_examples'
+# ToDo: Re-enable rubocop
+# rubocop:disable RSpec/EmptyExampleGroup
describe Views::CreateContract do
# it_behaves_like 'view contract', true do
# let(:view) do
@@ -66,3 +68,4 @@ describe Views::CreateContract do
# end
# end
end
+# rubocop:enable RSpec/EmptyExampleGroup
diff --git a/modules/storages/spec/factories/project_storage_factory.rb b/modules/storages/spec/factories/project_storage_factory.rb
index e4faff94fd7..e95a3759c67 100644
--- a/modules/storages/spec/factories/project_storage_factory.rb
+++ b/modules/storages/spec/factories/project_storage_factory.rb
@@ -28,7 +28,7 @@
# Required parameters: project and storage
FactoryBot.define do
- factory :project_storage, class: '::Storages::ProjectStorage' do |m|
+ factory :project_storage, class: '::Storages::ProjectStorage' do
creator factory: :user
end
end
diff --git a/modules/storages/spec/models/file_link_spec.rb b/modules/storages/spec/models/file_link_spec.rb
index 31b89557dac..d7033e33c26 100644
--- a/modules/storages/spec/models/file_link_spec.rb
+++ b/modules/storages/spec/models/file_link_spec.rb
@@ -53,7 +53,9 @@ describe ::Storages::FileLink, type: :model do
expect(file_link).to be_valid
end
- it "should fail when creating an instance with an unsupported container type" do
+ # ToDo: Finish test
+ # rubocop:disable Lint/UselessAssignment
+ it "fails when creating an instance with an unsupported container type" do
file_link = described_class.create(attributes.merge({ container_id: creator.id, container_type: "User" }))
# ToDo: expect(file_link).to be_invalid
end
@@ -63,6 +65,7 @@ describe ::Storages::FileLink, type: :model do
# ToDo: expect(file_link).to be_invalid
end
end
+ # rubocop:enable Lint/UselessAssignment
describe '#destroy' do
let(:file_link_to_destroy) { described_class.create(attributes) }
diff --git a/modules/storages/spec/models/project_storage_spec.rb b/modules/storages/spec/models/project_storage_spec.rb
index 01bcbcbfef9..41d3a16ae5f 100644
--- a/modules/storages/spec/models/project_storage_spec.rb
+++ b/modules/storages/spec/models/project_storage_spec.rb
@@ -30,7 +30,7 @@ require_relative '../spec_helper'
describe ::Storages::ProjectStorage, type: :model do
let(:creator) { create(:user) }
- let(:project) { create(:project, :enabled_module_names => %i[storages work_packages]) }
+ let(:project) { create(:project, enabled_module_names: %i[storages work_packages]) }
let(:storage) { create(:storage) }
let(:attributes) do
{
@@ -46,14 +46,14 @@ describe ::Storages::ProjectStorage, type: :model do
expect(project_storage).to be_valid
end
- context "having already one instance" do
+ context "when having already one instance" do
let(:old_project_storage) { described_class.create attributes }
before do
old_project_storage
end
- it "should fail if it is not unique per storage and project" do
+ it "fails if it is not unique per storage and project" do
expect(described_class.create(attributes.merge)).to be_invalid
end
end
@@ -71,10 +71,9 @@ describe ::Storages::ProjectStorage, type: :model do
project_storage_to_destroy.destroy
end
- it "should destroy all associated FileLink records" do
+ it "destroys all associated FileLink records" do
expect(Storages::ProjectStorage.count).to be 0
# ToDo: expect(Storages::FileLink.count).to be 0
end
end
end
-
diff --git a/modules/storages/spec/requests/api/v3/views/create_resource_spec.rb b/modules/storages/spec/requests/api/v3/views/create_resource_spec.rb
index 739483ab4cd..794b8e1c627 100644
--- a/modules/storages/spec/requests/api/v3/views/create_resource_spec.rb
+++ b/modules/storages/spec/requests/api/v3/views/create_resource_spec.rb
@@ -27,6 +27,7 @@
require 'spec_helper'
+# rubocop:disable RSpec/EmptyExampleGroup
describe ::API::V3::Views::ViewsAPI,
'create',
content_type: :json,
@@ -102,3 +103,4 @@ describe ::API::V3::Views::ViewsAPI,
# end
# end
end
+# rubocop:enable RSpec/EmptyExampleGroup
diff --git a/modules/storages/spec/routing/storages_routing_spec.rb b/modules/storages/spec/routing/storages_routing_spec.rb
index 6f9402e09f3..602e72dd672 100644
--- a/modules/storages/spec/routing/storages_routing_spec.rb
+++ b/modules/storages/spec/routing/storages_routing_spec.rb
@@ -28,6 +28,8 @@
require 'spec_helper'
+# ToDo:
+# rubocop:disable RSpec/EmptyExampleGroup
describe 'Storages routing', type: :routing do
# it 'routes to team_planner#index' do
# expect(subject)
@@ -35,3 +37,4 @@ describe 'Storages routing', type: :routing do
# .to(controller: 'team_planner/team_planner', action: 'index', project_id: 'foobar', state: 'state')
# end
end
+# rubocop:enable RSpec/EmptyExampleGroup
diff --git a/modules/storages/spec/spec_helper.rb b/modules/storages/spec/spec_helper.rb
index f54b5abead8..d4e0de3cda8 100644
--- a/modules/storages/spec/spec_helper.rb
+++ b/modules/storages/spec/spec_helper.rb
@@ -26,6 +26,10 @@
# See COPYRIGHT and LICENSE files for more details.
#++
+# This is the RSpec main include file that is included in basically every test case below.
+# See also: https://rspec.info/
+# ToDo: It loads factories and ??? what else?
+
# -- load spec_helper from OpenProject core
require 'spec_helper'
diff --git a/modules/storages/spec/support/pages/storage_tab.rb b/modules/storages/spec/support/pages/storage_tab.rb
deleted file mode 100644
index 49d3d3b05ab..00000000000
--- a/modules/storages/spec/support/pages/storage_tab.rb
+++ /dev/null
@@ -1,126 +0,0 @@
-#-- 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 COPYRIGHT and LICENSE files for more details.
-#++
-
-require 'support/pages/page'
-
-module Pages
- class StorageTab < ::Pages::Page
- attr_reader :project
-
- def initialize(project)
- super()
-
- @project = project
- end
- #
- # def path
- # project_team_planner_path(project)
- # end
- #
- # def expect_title(title = 'Unnamed team planner')
- # expect(page).to have_selector '.editable-toolbar-title--fixed', text: title
- # end
- #
- # def expect_empty_state(present: true)
- # expect(page).to have_conditional_selector(present, '.op-team-planner--no-data', text: 'Add assignees to set up your team planner.')
- # end
- #
- # def expect_assignee(user, present: true)
- # name = user.is_a?(User) ? user.name : user.to_s
- # expect(page).to have_conditional_selector(present, '.fc-resource', text: name, wait: 10)
- # end
- #
- # def add_item(assignee, start_date, end_date)
- # script = <<~JS
- # var event = new CustomEvent(
- # 'teamPlannerSelectDate',
- # {
- # detail: {
- # assignee: arguments[0],
- # start: arguments[1],
- # end: arguments[2]
- # }
- # });
- #
- # document.dispatchEvent(event);
- # JS
- #
- # page.execute_script(script, assignee, start_date, end_date)
- # ::Pages::SplitWorkPackageCreate.new project: project
- # end
- #
- # def remove_assignee(user)
- # page.find(%([data-qa-remove-assignee="#{user.id}"])).click
- # end
- #
- # def within_lane(user, &block)
- # raise ArgumentError.new("Expected instance of principal") unless user.is_a?(Principal)
- #
- # type = ::API::V3::Principals::PrincipalType.for(user)
- # href = ::API::V3::Utilities::PathHelper::ApiV3Path.send(type, user.id)
- #
- # page.within(%(.fc-timeline-lane[data-resource-id="#{href}"]), &block)
- # end
- #
- # def expect_event(work_package, present: true)
- # expect(page).to have_conditional_selector(present, '.fc-event', text: work_package.subject)
- # end
- #
- # def open_split_view(work_package)
- # page
- # .find('.fc-event', text: work_package.subject)
- # .click
- #
- # ::Pages::SplitWorkPackage.new(work_package, project)
- # end
- #
- # def add_assignee(name)
- # click_add_user
- # search_user_to_add name
- # select_user_to_add name
- # end
- #
- # def click_add_user
- # # Close the existing, if it is open
- # is_open = page.all('[data-qa-selector="tp-add-assignee"] input').first
- # page.find('[data-qa-selector="tp-assignee-add-button"]').click unless is_open
- # end
- #
- # def select_user_to_add(name)
- # select_autocomplete page.find('[data-qa-selector="tp-add-assignee"]'),
- # query: name,
- # results_selector: 'body'
- # end
- #
- # def search_user_to_add(name)
- # search_autocomplete page.find('[data-qa-selector="tp-add-assignee"]'),
- # query: name,
- # results_selector: 'body'
- # end
- end
-end