Merge pull request #11437 from opf/implementation/43677-extend-notification-representer-to-include-the-date-lines
[#43677] Extend Notification representer to include the date linespull/11536/head
commit
2b09649caf
@ -0,0 +1,45 @@ |
||||
# Example: Mentioned notification |
||||
--- |
||||
value: |
||||
_type: Notification |
||||
id: 1 |
||||
readIAN: false |
||||
reason: dateAlert |
||||
createdAt: '2022-04-05T14:38:28Z' |
||||
updatedAt: '2022-04-06T09:03:24Z' |
||||
_embedded: |
||||
project: |
||||
_hint: Project resource shortened for brevity |
||||
_type: Project |
||||
id: 11 |
||||
name: Jedi Remnant Locator |
||||
resource: |
||||
_hint: WorkPackage resource shortened for brevity |
||||
_type: WorkPackage |
||||
id: 77 |
||||
subject: Educate Visas Marr |
||||
details: |
||||
- _type: 'Values::Property' |
||||
property: 'startDate' |
||||
value: '2021-01-01' |
||||
_links: |
||||
self: |
||||
href: 'api/v3/notifications/123/details/0' |
||||
schema: |
||||
href: 'api/v3/values/schemas/startDate' |
||||
_links: |
||||
self: |
||||
href: '/api/v3/notifications/1' |
||||
readIAN: |
||||
href: '/api/v3/notifications/1/read_ian' |
||||
method: post |
||||
actor: |
||||
href: null |
||||
project: |
||||
href: '/api/v3/projects/11' |
||||
title: Jedi Remnant Locator |
||||
activity: |
||||
href: null |
||||
resource: |
||||
href: '/api/v3/work_packages/77' |
||||
title: Educate Visas Marr |
@ -0,0 +1,48 @@ |
||||
# Example: Mentioned notification |
||||
--- |
||||
value: |
||||
_type: Notification |
||||
id: 1 |
||||
readIAN: false |
||||
reason: mentioned |
||||
createdAt: '2022-04-05T14:38:28Z' |
||||
updatedAt: '2022-04-06T09:03:24Z' |
||||
_embedded: |
||||
author: |
||||
_hint: User resource shortened for brevity |
||||
_type: User |
||||
id: 13 |
||||
name: Darth Nihilus |
||||
project: |
||||
_hint: Project resource shortened for brevity |
||||
_type: Project |
||||
id: 11 |
||||
name: Jedi Remnant Locator |
||||
activity: |
||||
_hint: Activity resource shortened for brevity |
||||
_type: Activity::Comment |
||||
id: 180 |
||||
version: 3 |
||||
resource: |
||||
_hint: WorkPackage resource shortened for brevity |
||||
_type: WorkPackage |
||||
id: 77 |
||||
subject: Educate Visas Marr |
||||
details: [] |
||||
_links: |
||||
self: |
||||
href: '/api/v3/notifications/1' |
||||
readIAN: |
||||
href: '/api/v3/notifications/1/read_ian' |
||||
method: post |
||||
actor: |
||||
href: '/api/v3/users/13' |
||||
title: Darth Nihilus |
||||
project: |
||||
href: '/api/v3/projects/11' |
||||
title: Jedi Remnant Locator |
||||
activity: |
||||
href: '/api/v3/activities/180' |
||||
resource: |
||||
href: '/api/v3/work_packages/77' |
||||
title: Educate Visas Marr |
@ -0,0 +1,48 @@ |
||||
# Example: Notification collection |
||||
--- |
||||
value: |
||||
_type: Collection |
||||
count: 2 |
||||
total: 2 |
||||
offset: 1 |
||||
pageSize: 20 |
||||
_embedded: |
||||
elements: |
||||
- _hint: Notification resource shortened for brevity |
||||
id: 1 |
||||
readIAN: false |
||||
reason: mentioned |
||||
- _hint: Notification resource shortened for brevity |
||||
id: 2 |
||||
readIAN: false |
||||
reason: dateAlert |
||||
_embedded: |
||||
details: |
||||
- _type: 'Values::Property' |
||||
property: 'startDate' |
||||
value: '2021-01-01' |
||||
_links: |
||||
self: |
||||
href: 'api/v3/notifications/123/details/0' |
||||
schema: |
||||
href: 'api/v3/values/schemas/startDate' |
||||
detailsSchemas: |
||||
- _type: 'Schema' |
||||
property: |
||||
name: 'Property' |
||||
type: 'String' |
||||
value: |
||||
name: 'Start date' |
||||
type: 'Date' |
||||
_links: |
||||
self: |
||||
href: '/api/v3/values/schemas/startDate' |
||||
_links: |
||||
self: |
||||
href: '/api/v3/notifications?offset=1&pageSize=20' |
||||
jumpTo: |
||||
href: '/api/v3/notifications?filters=%5B%5D&offset=%7Boffset%7D&pageSize=20' |
||||
templated: true |
||||
changeSize: |
||||
href: '/api/v3/notifications?filters=%5B%5D&offset=1&pageSize=%7Bsize%7D' |
||||
templated: true |
@ -0,0 +1,13 @@ |
||||
# Example: Values::Property schema |
||||
--- |
||||
value: |
||||
_type: 'Schema' |
||||
property: |
||||
name: 'Property' |
||||
type: 'String' |
||||
value: |
||||
name: 'Start date' |
||||
type: 'Date' |
||||
_links: |
||||
self: |
||||
href: 'api/v3/values/schemas/startDate' |
@ -0,0 +1,11 @@ |
||||
# Example: Values::Property |
||||
--- |
||||
value: |
||||
_type: 'Values::Property' |
||||
property: 'startDate' |
||||
value: '2021-01-01' |
||||
_links: |
||||
self: |
||||
href: 'api/v3/notifications/123/details/0' |
||||
schema: |
||||
href: 'api/v3/values/schemas/startDate' |
@ -0,0 +1,39 @@ |
||||
# Schema: Values::PropertyModel |
||||
--- |
||||
type: object |
||||
required: |
||||
- _type |
||||
- property |
||||
- value |
||||
- _links |
||||
properties: |
||||
_type: |
||||
type: string |
||||
enum: |
||||
- Values::Property |
||||
property: |
||||
type: string |
||||
description: The key of the key - value pair represented by the Values::Property |
||||
value: |
||||
type: string |
||||
description: The value of the key - value pair represented by the Values::Property |
||||
_links: |
||||
type: object |
||||
required: |
||||
- self |
||||
- schema |
||||
properties: |
||||
self: |
||||
allOf: |
||||
- $ref: './link.yml' |
||||
- description: |- |
||||
This key - value pair. |
||||
|
||||
**Resource**: Storage |
||||
schema: |
||||
allOf: |
||||
- $ref: './link.yml' |
||||
- description: |- |
||||
The schema describing the key - value pair. |
||||
|
||||
**Resource**: Schema |
@ -0,0 +1,47 @@ |
||||
# /api/v3/notifications/{notification_id}/details/{id} |
||||
--- |
||||
get: |
||||
summary: Get a notification detail |
||||
operationId: view_notification_detail |
||||
tags: |
||||
- Notifications |
||||
- Values::Property |
||||
description: Returns an individual detail of a notification identified by the notification id and the id of the detail. |
||||
parameters: |
||||
- name: notification_id |
||||
in: path |
||||
description: notification id |
||||
example: '1' |
||||
required: true |
||||
schema: |
||||
type: integer |
||||
- name: id |
||||
in: path |
||||
description: detail id |
||||
example: '0' |
||||
required: true |
||||
schema: |
||||
type: integer |
||||
responses: |
||||
'200': |
||||
content: |
||||
application/hal+json: |
||||
schema: |
||||
$ref: '../components/schemas/values_property_model.yml' |
||||
examples: |
||||
'Start date notification detail': |
||||
$ref: '../components/examples/values_property_start_date.yml' |
||||
description: OK |
||||
'404': |
||||
content: |
||||
application/hal+json: |
||||
schema: |
||||
$ref: '../components/schemas/error_response.yml' |
||||
example: |
||||
_type: Error |
||||
errorIdentifier: urn:openproject-org:api:v3:errors:NotFound |
||||
message: The requested resource could not be found. |
||||
description: |- |
||||
Returned if the notification or the detail of it does not exist or if the user does not have permission to view it. |
||||
|
||||
**Required permission** being recipient of the notification |
@ -0,0 +1,51 @@ |
||||
# /api/v3/values/schemas/{id} |
||||
--- |
||||
get: |
||||
parameters: |
||||
- name: id |
||||
in: path |
||||
description: |- |
||||
The identifier of the value. This is typically the value of the `property` property of |
||||
the `Values` resource. It should be in lower camelcase format. |
||||
example: 'startDate' |
||||
required: true |
||||
schema: |
||||
type: string |
||||
responses: |
||||
'200': |
||||
content: |
||||
application/hal+json: |
||||
schema: |
||||
"$ref": "../components/schemas/schema_model.yml" |
||||
examples: |
||||
'Values::Property Start date schema': |
||||
$ref: '../components/examples/values_property_schema.yml' |
||||
description: OK |
||||
headers: {} |
||||
'404': |
||||
content: |
||||
application/hal+json: |
||||
schema: |
||||
$ref: '../components/schemas/error_response.yml' |
||||
example: |
||||
_type: Error |
||||
errorIdentifier: urn:openproject-org:api:v3:errors:NotFound |
||||
message: The requested resource could not be found. |
||||
description: |- |
||||
Returned if the schema does not exist. |
||||
'400': |
||||
content: |
||||
application/hal+json: |
||||
schema: |
||||
$ref: '../components/schemas/error_response.yml' |
||||
example: |
||||
_type: Error |
||||
errorIdentifier: urn:openproject-org:api:v3:errors:BadRequest |
||||
message: "Bad request: property is invalid" |
||||
description: |- |
||||
Returned if the requested property id is not in a lower camel case format. |
||||
tags: |
||||
- Values::Property |
||||
description: The schema of a `Values` resource. |
||||
operationId: View_values_schema |
||||
summary: View Values schema |
@ -0,0 +1,23 @@ |
||||
--- |
||||
description: |- |
||||
`Values::Property` represents a single key - value pair. That pair typically is an |
||||
excerpt of the properties of a resource. `Values::Property` itself is not an independent resource. It will always be nested and as such |
||||
will only exist as part of another resource. |
||||
|
||||
It is currently used e.g. in the Notification resource. |
||||
|
||||
## Linked Properties |
||||
|
||||
| Property | Description | Type | Constraints | Supported operations | Condition | |
||||
| :--------------: | ----------------------------| ----------- | --------------------- | -------------------- | ------------------------- | |
||||
| self | This value | Values::Property | not null | READ | | |
||||
| schema | This value's schema | Schema | not null | READ | | |
||||
|
||||
## Local Properties |
||||
|
||||
| Property | Description | Type | Constraints | Supported operations | Condition | |
||||
| :--------------: | ------------------------------------------------------ | ----------- | -------------- | -------------------- | ---------------------------- | |
||||
| property | The pairs' key name | String | not null | READ | | |
||||
| value | The pairs' value | Polymorphic | | READ | | |
||||
|
||||
name: Values::Property |
@ -0,0 +1,74 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API |
||||
module Decorators |
||||
module SelfLink |
||||
def self.included(base) |
||||
base.extend ClassMethods |
||||
end |
||||
|
||||
def self.prepended(base) |
||||
base.extend ClassMethods |
||||
end |
||||
|
||||
def self_v3_path(path, id_attribute) |
||||
path ||= _type.underscore |
||||
|
||||
id = if id_attribute.respond_to?(:call) |
||||
instance_eval(&id_attribute) |
||||
else |
||||
represented.send(id_attribute) |
||||
end |
||||
|
||||
id = [nil] if id.nil? |
||||
|
||||
api_v3_paths.send(path, *Array(id)) |
||||
end |
||||
|
||||
module ClassMethods |
||||
def self_link(path: nil, |
||||
id_attribute: :id, |
||||
title: true, |
||||
title_getter: ->(*) { represented.name }) |
||||
link :self do |
||||
self_path = self_v3_path(path, id_attribute) |
||||
|
||||
link_object = { href: self_path } |
||||
if title |
||||
title_string = instance_eval(&title_getter) |
||||
link_object[:title] = title_string if title_string |
||||
end |
||||
|
||||
link_object |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,52 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Notifications |
||||
module DetailsFactory |
||||
extend ::API::V3::Utilities::PathHelper |
||||
|
||||
module_function |
||||
|
||||
def for(notification) |
||||
concrete_factory_for(notification.reason) |
||||
.for(notification) |
||||
end |
||||
|
||||
def concrete_factory_for(reason) |
||||
@concrete_factory_for ||= Hash.new do |h, reason_key| |
||||
h[reason_key] = if API::V3::Notifications::DetailsFactory.const_defined?(reason_key.camelcase) |
||||
"API::V3::Notifications::DetailsFactory::#{reason_key.camelcase}".constantize |
||||
else |
||||
API::V3::Notifications::DetailsFactory::Default |
||||
end |
||||
end |
||||
|
||||
@concrete_factory_for[reason] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Notifications::DetailsFactory |
||||
module DateAlertDueDate |
||||
extend ::API::V3::Utilities::PathHelper |
||||
|
||||
module_function |
||||
|
||||
def for(notification) |
||||
[ |
||||
::API::V3::Values::PropertyDateRepresenter |
||||
.new(::API::V3::Values::PropertyModel.new(:due_date, notification.resource.due_date), |
||||
self_link: api_v3_paths.notification_detail(notification.id, 0)) |
||||
] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Notifications::DetailsFactory |
||||
module DateAlertStartDate |
||||
extend ::API::V3::Utilities::PathHelper |
||||
|
||||
module_function |
||||
|
||||
def for(notification) |
||||
[ |
||||
::API::V3::Values::PropertyDateRepresenter |
||||
.new(::API::V3::Values::PropertyModel.new(:start_date, notification.resource.start_date), |
||||
self_link: api_v3_paths.notification_detail(notification.id, 0)) |
||||
] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Notifications::DetailsFactory |
||||
module Default |
||||
module_function |
||||
|
||||
def for(_notification) |
||||
[] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values |
||||
class PropertyDateRepresenter < PropertyRepresenter |
||||
include API::Decorators::DateProperty |
||||
|
||||
date_property :value |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values |
||||
class PropertyModel |
||||
attr_reader :property, |
||||
:value |
||||
|
||||
def initialize(property, value) |
||||
@property = property |
||||
@value = value |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,64 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values |
||||
class PropertyRepresenter < ::Roar::Decorator |
||||
include ::Roar::JSON::HAL |
||||
include ::Roar::Hypermedia |
||||
include ::API::Decorators::SelfLink |
||||
include ::API::V3::Utilities::PathHelper |
||||
|
||||
def initialize(model, self_link:) |
||||
@self_link = self_link |
||||
|
||||
super(model) |
||||
end |
||||
|
||||
property :_type, |
||||
getter: ->(*) { 'Values::Property' } |
||||
|
||||
property :property, |
||||
getter: ->(*) { property.to_s.camelcase(:lower) } |
||||
|
||||
self_link title: false |
||||
|
||||
link :schema do |
||||
{ |
||||
href: api_v3_paths.value_schema(represented.property.to_s.camelcase(:lower)) |
||||
} |
||||
end |
||||
|
||||
def self_v3_path(*_args) |
||||
self_link |
||||
end |
||||
|
||||
private |
||||
|
||||
attr_reader :self_link |
||||
end |
||||
end |
@ -0,0 +1,44 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values::Schemas |
||||
class Model |
||||
attr_reader :name, |
||||
:type |
||||
|
||||
def initialize(name, type) |
||||
@name = name |
||||
@type = type |
||||
end |
||||
|
||||
def ==(other) |
||||
name == other.name && |
||||
type == other.type |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values::Schemas |
||||
class PropertySchemaRepresenter < ::API::Decorators::SchemaRepresenter |
||||
schema :property, |
||||
type: 'String', |
||||
name_source: ->(*) { I18n.t(:'api_v3.attributes.property') } |
||||
|
||||
schema :value, |
||||
type: ->(*) { represented.type }, |
||||
name_source: ->(*) { represented.name } |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values::Schemas |
||||
class ValueSchemaAPI < ::API::OpenProjectAPI |
||||
resources :schemas do |
||||
params do |
||||
requires :property, desc: 'Name of the schema property', regexp: /^[a-z][a-zA-Z0-9]*$/ |
||||
end |
||||
|
||||
get ':property' do |
||||
ValueSchemaFactory.for(params[:property].underscore).tap do |representer| |
||||
raise API::Errors::NotFound unless representer |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,73 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values::Schemas |
||||
module ValueSchemaFactory |
||||
extend ::API::V3::Utilities::PathHelper |
||||
SUPPORTED = %w(start_date due_date).freeze |
||||
|
||||
module_function |
||||
|
||||
def for(property) |
||||
return nil unless supported?(property) |
||||
|
||||
::API::V3::Values::Schemas::PropertySchemaRepresenter |
||||
.new(model_for(property), |
||||
current_user: nil, |
||||
self_link: api_v3_paths.value_schema(property.camelcase(:lower))) |
||||
end |
||||
|
||||
def all |
||||
SUPPORTED.map { |property| self.for(property) } |
||||
end |
||||
|
||||
def supported?(property) |
||||
# This is but a stub. Currently, only 'start_date' and 'due_date' |
||||
# need to be supported so this simple approach works. |
||||
SUPPORTED.include?(property) |
||||
end |
||||
|
||||
def model_for(property) |
||||
API::V3::Values::Schemas::Model |
||||
.new(i18n_for(property), |
||||
type_for(property)) |
||||
end |
||||
|
||||
def i18n_for(property) |
||||
# This is but a stub. Currently, only 'start_date' and 'due_date' |
||||
# need to be supported so this simple approach works. |
||||
I18n.t("attributes.#{property}") |
||||
end |
||||
|
||||
def type_for(_property) |
||||
# This is but a stub. Currently, only 'start_date' and 'due_date' |
||||
# need to be supported so this simple approach works. |
||||
'Date' |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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. |
||||
# ++ |
||||
|
||||
module API::V3::Values |
||||
class ValuesAPI < ::API::OpenProjectAPI |
||||
resources :values do |
||||
mount API::V3::Values::Schemas::ValueSchemaAPI |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,80 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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 'spec_helper' |
||||
|
||||
describe ::API::V3::Notifications::DetailsFactory do |
||||
let(:resource) { build_stubbed(:work_package) } |
||||
|
||||
let(:notification) do |
||||
build_stubbed(:notification, |
||||
resource:, |
||||
reason:) |
||||
end |
||||
|
||||
describe '.for' do |
||||
context 'for a date_alert_start_date notification' do |
||||
let(:reason) { :date_alert_start_date } |
||||
|
||||
it 'returns one detail' do |
||||
expect(described_class.for(notification).size) |
||||
.to eq 1 |
||||
end |
||||
|
||||
it 'returns an array of `Values::Property` representers' do |
||||
expect(described_class.for(notification)[0]) |
||||
.to be_a ::API::V3::Values::PropertyDateRepresenter |
||||
end |
||||
end |
||||
|
||||
context 'for a date_alert_due_date notification' do |
||||
let(:reason) { :date_alert_due_date } |
||||
|
||||
it 'returns one detail' do |
||||
expect(described_class.for(notification).size) |
||||
.to eq 1 |
||||
end |
||||
|
||||
it 'returns an array of `Values::Property` representers' do |
||||
expect(described_class.for(notification)[0]) |
||||
.to be_a ::API::V3::Values::PropertyDateRepresenter |
||||
end |
||||
end |
||||
|
||||
(Notification::REASONS.keys - %i[date_alert_start_date date_alert_due_date]).each do |possible_reason| |
||||
context "for a #{possible_reason} notification" do |
||||
let(:reason) { possible_reason } |
||||
|
||||
it 'is an empty array' do |
||||
expect(described_class.for(notification)) |
||||
.to eq [] |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,84 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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 'spec_helper' |
||||
|
||||
describe ::API::V3::Values::PropertyDateRepresenter, 'rendering' do |
||||
subject(:generated) { representer.to_json } |
||||
|
||||
let(:property) { 'abc' } |
||||
let(:date_value) { Date.current } |
||||
let(:key_value) { Struct.new(:property, :value, keyword_init: true).new(property:, value: date_value) } |
||||
let(:self_link) { 'api/bogus/value' } |
||||
let(:representer) do |
||||
described_class.new key_value, self_link: |
||||
end |
||||
|
||||
describe 'self link' do |
||||
it_behaves_like 'has an untitled link' do |
||||
let(:link) { 'self' } |
||||
let(:href) { self_link } |
||||
end |
||||
end |
||||
|
||||
describe 'properties' do |
||||
describe '_type' do |
||||
it_behaves_like 'property', :_type do |
||||
let(:value) { 'Values::Property' } |
||||
end |
||||
end |
||||
|
||||
describe 'property' do |
||||
it_behaves_like 'property', :property do |
||||
let(:value) { property } |
||||
end |
||||
|
||||
context 'with a snake_case property' do |
||||
let(:property) { 'snake_case' } |
||||
|
||||
it_behaves_like 'property', :property do |
||||
let(:value) { 'snakeCase' } |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'value' do |
||||
it_behaves_like 'date property', :value do |
||||
let(:value) { date_value } |
||||
end |
||||
|
||||
context 'with an empty value' do |
||||
let(:date_value) { nil } |
||||
|
||||
it_behaves_like 'date property', :value do |
||||
let(:value) { nil } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,90 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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 'spec_helper' |
||||
|
||||
describe ::API::V3::Values::Schemas::PropertySchemaRepresenter, 'rendering' do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:current_user) { build_stubbed(:user) } |
||||
|
||||
let(:self_link) { '/a/self/link' } |
||||
|
||||
let(:model) do |
||||
API::V3::Values::Schemas::Model |
||||
.new('The start date to that object', |
||||
'ADate') |
||||
end |
||||
|
||||
let(:representer) do |
||||
described_class.create(model, |
||||
self_link:, |
||||
current_user:) |
||||
end |
||||
|
||||
subject(:generated) { representer.to_json } |
||||
|
||||
describe '_type' do |
||||
it 'is indicated as Schema' do |
||||
expect(subject) |
||||
.to be_json_eql('Schema'.to_json) |
||||
.at_path('_type') |
||||
end |
||||
end |
||||
|
||||
describe 'property' do |
||||
let(:path) { 'property' } |
||||
|
||||
it_behaves_like 'has basic schema properties' do |
||||
let(:type) { 'String' } |
||||
let(:name) { I18n.t(:'api_v3.attributes.property') } |
||||
let(:required) { true } |
||||
let(:writable) { false } |
||||
end |
||||
end |
||||
|
||||
describe 'value' do |
||||
let(:path) { 'value' } |
||||
|
||||
it_behaves_like 'has basic schema properties' do |
||||
let(:type) { model.type } |
||||
let(:name) { model.name } |
||||
let(:required) { true } |
||||
let(:writable) { false } |
||||
end |
||||
end |
||||
|
||||
describe '_links' do |
||||
describe 'self' do |
||||
it_behaves_like 'has an untitled link' do |
||||
let(:link) { 'self' } |
||||
let(:href) { self_link } |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,91 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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 'spec_helper' |
||||
|
||||
describe ::API::V3::Values::Schemas::ValueSchemaFactory do |
||||
include ::API::V3::Utilities::PathHelper |
||||
|
||||
describe '.for' do |
||||
let!(:representer_instance) do |
||||
instance_double(::API::V3::Values::Schemas::PropertySchemaRepresenter) |
||||
end |
||||
let!(:representer_class) do |
||||
allow(::API::V3::Values::Schemas::PropertySchemaRepresenter) |
||||
.to receive(:new) |
||||
.and_return(representer_instance) |
||||
end |
||||
|
||||
context 'for the start_date property' do |
||||
let(:property) { 'start_date' } |
||||
|
||||
it 'returns a schema representer' do |
||||
expect(described_class.for(property)) |
||||
.to eq representer_instance |
||||
end |
||||
|
||||
it 'instantiates the representer with the proper params' do |
||||
described_class.for(property) |
||||
|
||||
expect(::API::V3::Values::Schemas::PropertySchemaRepresenter) |
||||
.to have_received(:new) |
||||
.with(API::V3::Values::Schemas::Model.new(I18n.t('attributes.start_date'), 'Date'), |
||||
current_user: nil, |
||||
self_link: api_v3_paths.value_schema(property.camelcase(:lower))) |
||||
end |
||||
end |
||||
|
||||
context 'for the due_date property' do |
||||
let(:property) { 'due_date' } |
||||
|
||||
it 'returns a schema representer' do |
||||
expect(described_class.for(property)) |
||||
.to eq representer_instance |
||||
end |
||||
|
||||
it 'instantiates the representer with the proper params' do |
||||
described_class.for(property) |
||||
|
||||
expect(::API::V3::Values::Schemas::PropertySchemaRepresenter) |
||||
.to have_received(:new) |
||||
.with(API::V3::Values::Schemas::Model.new(I18n.t('attributes.due_date'), 'Date'), |
||||
current_user: nil, |
||||
self_link: api_v3_paths.value_schema(property.camelcase(:lower))) |
||||
end |
||||
end |
||||
|
||||
context 'for another property' do |
||||
let(:property) { 'bogus' } |
||||
|
||||
it 'returns nil' do |
||||
expect(described_class.for(property)) |
||||
.to be_nil |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,141 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2020 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 'spec_helper' |
||||
|
||||
describe ::API::V3::Notifications::NotificationsAPI, |
||||
'fetch notification details', |
||||
content_type: :json do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
shared_let(:project) { create(:project) } |
||||
shared_let(:resource) do |
||||
create(:work_package, |
||||
project:, |
||||
start_date: Date.yesterday, |
||||
due_date: Date.tomorrow) |
||||
end |
||||
shared_let(:recipient) do |
||||
create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: %i[view_work_packages]) |
||||
end |
||||
|
||||
let(:notification) { create(:notification, recipient:, resource:, project:, reason:) } |
||||
let(:reason) { :date_alert_start_date } |
||||
|
||||
# We have 1 detail item at maximum, and the id is coming |
||||
# from the detail's array index which is 0 |
||||
let(:detail_id) { 0 } |
||||
let(:notification_detail_path) { api_v3_paths.notification_detail(notification.id, detail_id) } |
||||
let(:send_request) do |
||||
get notification_detail_path |
||||
end |
||||
|
||||
let(:parsed_response) { JSON.parse(last_response.body) } |
||||
|
||||
before do |
||||
login_as current_user |
||||
end |
||||
|
||||
describe 'recipient user' do |
||||
let(:current_user) { recipient } |
||||
|
||||
context 'for a non dateAlert notification' do |
||||
let(:reason) { :mentioned } |
||||
|
||||
it 'returns a 404 response' do |
||||
send_request |
||||
expect(last_response.status).to eq(404) |
||||
end |
||||
end |
||||
|
||||
context 'for a start date alert notification' do |
||||
let(:reason) { :date_alert_start_date } |
||||
|
||||
it 'can get the notification details for a start date' do |
||||
send_request |
||||
expect(last_response.body) |
||||
.to be_json_eql('startDate'.to_json) |
||||
.at_path('property') |
||||
expect(last_response.body) |
||||
.to be_json_eql(::API::V3::Utilities::DateTimeFormatter.format_date(resource.start_date).to_json) |
||||
.at_path('value') |
||||
expect(last_response.body) |
||||
.to be_json_eql(notification_detail_path.to_json) |
||||
.at_path('_links/self/href') |
||||
expect(last_response.body) |
||||
.to be_json_eql("/api/v3/values/schemas/startDate".to_json) |
||||
.at_path('_links/schema/href') |
||||
end |
||||
end |
||||
|
||||
context 'for a due date alert notification' do |
||||
let(:reason) { :date_alert_due_date } |
||||
|
||||
it 'can get the notification details for a due date' do |
||||
send_request |
||||
expect(last_response.body) |
||||
.to be_json_eql('dueDate'.to_json) |
||||
.at_path('property') |
||||
expect(last_response.body) |
||||
.to be_json_eql(::API::V3::Utilities::DateTimeFormatter.format_date(resource.due_date).to_json) |
||||
.at_path('value') |
||||
expect(last_response.body) |
||||
.to be_json_eql(notification_detail_path.to_json) |
||||
.at_path('_links/self/href') |
||||
expect(last_response.body) |
||||
.to be_json_eql("/api/v3/values/schemas/dueDate".to_json) |
||||
.at_path('_links/schema/href') |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'admin user' do |
||||
current_user { build_stubbed(:admin) } |
||||
|
||||
before do |
||||
send_request |
||||
end |
||||
|
||||
it 'returns a 404 response' do |
||||
expect(last_response.status).to eq(404) |
||||
end |
||||
end |
||||
|
||||
describe 'unauthorized user' do |
||||
current_user { build_stubbed(:user) } |
||||
|
||||
before do |
||||
send_request |
||||
end |
||||
|
||||
it 'returns a 404 response' do |
||||
expect(last_response.status).to eq(404) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,100 @@ |
||||
# --copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2010-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. |
||||
# |
||||
# 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 'spec_helper' |
||||
|
||||
describe ::API::V3::Values::Schemas::ValueSchemaAPI, |
||||
'show', |
||||
content_type: :json do |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
current_user { build_stubbed(:user) } |
||||
|
||||
let(:path) { api_v3_paths.value_schema(schema_id) } |
||||
let(:schema_id) { 'bogus' } |
||||
|
||||
before do |
||||
get path |
||||
end |
||||
|
||||
context 'for a logged in user' do |
||||
context 'for a startDate' do |
||||
let(:schema_id) { 'startDate' } |
||||
|
||||
it 'returns the schema', :aggregate_failures do |
||||
expect(last_response.status) |
||||
.to eq 200 |
||||
|
||||
expect(last_response.body) |
||||
.to be_json_eql('Schema'.to_json) |
||||
.at_path('_type') |
||||
|
||||
expect(last_response.body) |
||||
.to be_json_eql('Date'.to_json) |
||||
.at_path('value/type') |
||||
|
||||
expect(last_response.body) |
||||
.to be_json_eql('Start date'.to_json) |
||||
.at_path('value/name') |
||||
end |
||||
end |
||||
|
||||
context 'for a dueDate' do |
||||
let(:schema_id) { 'dueDate' } |
||||
|
||||
it 'returns the schema', :aggregate_failures do |
||||
expect(last_response.status) |
||||
.to eq 200 |
||||
|
||||
expect(last_response.body) |
||||
.to be_json_eql('Schema'.to_json) |
||||
.at_path('_type') |
||||
|
||||
expect(last_response.body) |
||||
.to be_json_eql('Date'.to_json) |
||||
.at_path('value/type') |
||||
|
||||
expect(last_response.body) |
||||
.to be_json_eql('Finish date'.to_json) |
||||
.at_path('value/name') |
||||
end |
||||
end |
||||
|
||||
context 'for a non existing property' do |
||||
let(:schema_id) { 'bogus' } |
||||
|
||||
it_behaves_like 'not found' |
||||
end |
||||
|
||||
context 'for an underscore property' do |
||||
let(:schema_id) { 'start_date' } |
||||
|
||||
it_behaves_like 'param validation error' |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue