parent
f85032559d
commit
8a08856748
@ -0,0 +1,51 @@ |
||||
# Group Custom Objects |
||||
|
||||
## Linked Properties |
||||
| Link | Description | Type | Constraints | Supported operations | |
||||
|:-------------:|-------------------------- | ------------- | ----------- | -------------------- | |
||||
| self | This custom object | CustomObject | not null | READ | |
||||
|
||||
## Local Properties |
||||
| Property | Description | Type | Constraints | Supported operations | |
||||
|:----------------:| ---------------------------------------------- | -------- | ----------- | -------------------- | |
||||
| id | The identifier | Integer | | READ | |
||||
| value | The value defined for this custom object | String | | READ | |
||||
|
||||
|
||||
Custom objects are options of list custom fields. |
||||
|
||||
## Custom Object [/api/v3/custom_objects/{id}] |
||||
|
||||
+ Model |
||||
+ Body |
||||
|
||||
{ |
||||
"_links": { |
||||
"self": { "href": "/api/v3/custom_objects/1" } |
||||
}, |
||||
"_type": "CustomObject", |
||||
"value": "Foo" |
||||
} |
||||
|
||||
## View Custom Object [GET] |
||||
|
||||
+ Parameters |
||||
+ id (required, integer, `1`) ... The custom object's identifier |
||||
|
||||
+ Response 200 (application/hal+json) |
||||
|
||||
[Custom Object][] |
||||
|
||||
+ Response 404 (application/hal+json) |
||||
|
||||
Returned if the custom object does not exist or the client does not have sufficient permissions to see it. |
||||
|
||||
**Required permission:** view work package in any project the custom object's custom field is active in. |
||||
|
||||
+ Body |
||||
|
||||
{ |
||||
"_type": "Error", |
||||
"errorIdentifier": "urn:openproject-org:api:v3:errors:NotFound", |
||||
"message": "The specified resource does not exist." |
||||
} |
@ -0,0 +1,10 @@ |
||||
<span> |
||||
<div ng-repeat="value in vm.field.value" title="{{ value }}" class="custom-option -multiple-lines"> |
||||
{{ value }} |
||||
</div> |
||||
|
||||
<div title="I18n.t('js.work_packages.no_value')" ng-if="vm.field.value.length == 0" class="custom-option -empty"> |
||||
- |
||||
</div> |
||||
</span> |
||||
|
@ -1,40 +0,0 @@ |
||||
// -- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||||
//
|
||||
// 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 doc/COPYRIGHT.rdoc for more details.
|
||||
// ++
|
||||
|
||||
import {DisplayField} from "../wp-display-field/wp-display-field.module"; |
||||
|
||||
export class StringObjectDisplayField extends DisplayField { |
||||
public get value() { |
||||
if(this.schema) { |
||||
return this.resource[this.name] && (this.resource[this.name].value || this.resource[this.name].name); |
||||
} |
||||
else { |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,48 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module CustomOptions |
||||
class CustomOptionRepresenter < ::API::Decorators::Single |
||||
self_link |
||||
|
||||
# TODO: add link to custom field once api for custom fields exists |
||||
|
||||
def _type |
||||
'CustomOption' |
||||
end |
||||
|
||||
property :id |
||||
|
||||
property :value |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,67 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module CustomOptions |
||||
class CustomOptionsAPI < ::API::OpenProjectAPI |
||||
resources :custom_options do |
||||
namespace ':id' do |
||||
params do |
||||
requires :id, type: Integer |
||||
end |
||||
|
||||
helpers do |
||||
def authorize_view_in_activated_project(custom_option) |
||||
allowed = Project |
||||
.allowed_to(current_user, :view_work_packages) |
||||
.joins(:work_package_custom_fields) |
||||
.where(custom_fields: { id: custom_option.custom_field_id }) |
||||
.exists? |
||||
|
||||
unless allowed |
||||
raise API::Errors::NotFound |
||||
end |
||||
end |
||||
end |
||||
|
||||
get do |
||||
co = CustomOption.find(params[:id]) |
||||
|
||||
authorize_view_in_activated_project(co) |
||||
|
||||
CustomOptionRepresenter.new(co, current_user: current_user) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
FactoryGirl.define do |
||||
factory :custom_option do |
||||
sequence(:value) { |n| "Custom Option #{n}" } |
||||
end |
||||
end |
@ -0,0 +1,64 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe ::API::V3::CustomOptions::CustomOptionRepresenter do |
||||
include ::API::V3::Utilities::PathHelper |
||||
|
||||
let(:custom_option) { FactoryGirl.build_stubbed(:custom_option, custom_field: custom_field) } |
||||
let(:custom_field) { FactoryGirl.build_stubbed(:list_wp_custom_field) } |
||||
let(:user) { FactoryGirl.build_stubbed(:user) } |
||||
let(:representer) do |
||||
described_class.new(custom_option, current_user: user) |
||||
end |
||||
|
||||
subject { representer.to_json } |
||||
|
||||
describe 'generation' do |
||||
describe '_links' do |
||||
it_behaves_like 'has a titled link' do |
||||
let(:link) { 'self' } |
||||
let(:href) { api_v3_paths.custom_option custom_option.id } |
||||
let(:title) { custom_option.to_s } |
||||
end |
||||
end |
||||
|
||||
it 'has the type "CustomOption"' do |
||||
is_expected.to be_json_eql('CustomOption'.to_json).at_path('_type') |
||||
end |
||||
|
||||
it 'has an id' do |
||||
is_expected.to be_json_eql(custom_option.id.to_json).at_path('id') |
||||
end |
||||
|
||||
it 'has a value' do |
||||
is_expected.to be_json_eql(custom_option.to_s.to_json).at_path('value') |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,119 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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-2017 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'rack/test' |
||||
|
||||
describe 'API v3 Custom Options resource' do |
||||
include Rack::Test::Methods |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:user) do |
||||
FactoryGirl.create(:user, |
||||
member_in_project: project, |
||||
member_through_role: role) |
||||
end |
||||
let(:project) { FactoryGirl.create(:project) } |
||||
let(:role) { FactoryGirl.create(:role, permissions: permissions) } |
||||
let(:permissions) { [:view_work_packages] } |
||||
let(:custom_field) do |
||||
cf = FactoryGirl.create(:list_wp_custom_field) |
||||
|
||||
project.work_package_custom_fields << cf |
||||
|
||||
cf |
||||
end |
||||
let(:custom_option) do |
||||
FactoryGirl.create(:custom_option, |
||||
custom_field: custom_field) |
||||
end |
||||
|
||||
subject(:response) { last_response } |
||||
|
||||
describe 'GET api/v3/custom_options/:id' do |
||||
let(:path) { api_v3_paths.custom_option custom_option.id } |
||||
|
||||
before do |
||||
allow(User) |
||||
.to receive(:current) |
||||
.and_return(user) |
||||
get path |
||||
end |
||||
|
||||
context 'when being allowed' do |
||||
it 'is successful' do |
||||
expect(subject.status) |
||||
.to eql(200) |
||||
end |
||||
|
||||
it 'returns the custom option' do |
||||
expect(response.body) |
||||
.to be_json_eql('CustomOption'.to_json) |
||||
.at_path('_type') |
||||
|
||||
expect(response.body) |
||||
.to be_json_eql(custom_option.id.to_json) |
||||
.at_path('id') |
||||
|
||||
expect(response.body) |
||||
.to be_json_eql(custom_option.value.to_json) |
||||
.at_path('value') |
||||
end |
||||
end |
||||
|
||||
context 'when lacking permission' do |
||||
let(:permissions) { [] } |
||||
|
||||
it 'is 404' do |
||||
expect(subject.status) |
||||
.to eql(404) |
||||
end |
||||
end |
||||
|
||||
context 'when custom option not in project' do |
||||
let(:custom_field) do |
||||
# not added to project |
||||
FactoryGirl.create(:list_wp_custom_field) |
||||
end |
||||
|
||||
it 'is 404' do |
||||
expect(subject.status) |
||||
.to eql(404) |
||||
end |
||||
end |
||||
|
||||
context 'when not existing' do |
||||
let(:path) { api_v3_paths.custom_option 0 } |
||||
|
||||
it 'is 404' do |
||||
expect(subject.status) |
||||
.to eql(404) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue