commit
292c930591
@ -0,0 +1,30 @@ |
|||||||
|
/*-- copyright |
||||||
|
* OpenProject is a project management system. |
||||||
|
* Copyright (C) 2012-2013 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. ++ |
||||||
|
*/ |
||||||
|
|
||||||
|
.nothing-to-preview |
||||||
|
color: red |
@ -1,50 +0,0 @@ |
|||||||
<%#-- copyright |
|
||||||
OpenProject is a project management system. |
|
||||||
Copyright (C) 2012-2014 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. |
|
||||||
|
|
||||||
++#%> |
|
||||||
|
|
||||||
<% if work_package.journal_notes.present? %> |
|
||||||
<fieldset class="preview"> |
|
||||||
<legend> |
|
||||||
<%= Journal.human_attribute_name(:notes) %> |
|
||||||
</legend> |
|
||||||
|
|
||||||
<%= textilizable work_package.journal_notes, |
|
||||||
:object => work_package %> |
|
||||||
</fieldset> |
|
||||||
<% end %> |
|
||||||
|
|
||||||
<% if work_package.description.present? %> |
|
||||||
<fieldset class="preview"> |
|
||||||
<legend> |
|
||||||
<%= WorkPackage.human_attribute_name(:description) %> |
|
||||||
</legend> |
|
||||||
|
|
||||||
<%= textilizable work_package.description, |
|
||||||
:object => work_package %> |
|
||||||
</fieldset> |
|
||||||
<% end %> |
|
@ -0,0 +1,109 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2014 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. |
||||||
|
#++ |
||||||
|
|
||||||
|
################################################################################ |
||||||
|
# This concern provides a general implementation of preview functionality # |
||||||
|
# found in different controllers. # |
||||||
|
# # |
||||||
|
# Nevertheless, this concern expects the controller to implement the function # |
||||||
|
# #parse_preview_data. #parse_preview_data must return a list of (wiki) texts, # |
||||||
|
# attachments required to render the texts, and the object. Attachments and # |
||||||
|
# object may be nil. # |
||||||
|
# # |
||||||
|
# You may use #parse_preview_data_helper to implement #parse_preview_data. # |
||||||
|
# Then, a minimal implementation of #parse_preview_data may looks as follows: # |
||||||
|
# # |
||||||
|
# def parse_preview_data # |
||||||
|
# parse_preview_data_helper :work_packages, [:description, :notes] # |
||||||
|
# end # |
||||||
|
# # |
||||||
|
# The first parameter 'param_name' specifies the key in the params object that # |
||||||
|
# contains the values. The second parameter 'attributes' speciffies the value # |
||||||
|
# keys. Optionally, if 'param_name' is not equivallent to a class name, you # |
||||||
|
# can pass the objects class as third parameter. # |
||||||
|
# # |
||||||
|
# For object identification #parse_preview_data_helper uses the params # |
||||||
|
# object's 'id' key, if available. If 'id' needs some preprocessing or is not # |
||||||
|
# the id to the object instance, you may override #parse_preview_id to provide # |
||||||
|
# a different id. # |
||||||
|
################################################################################ |
||||||
|
module OpenProject::Concerns::Preview |
||||||
|
extend ActiveSupport::Concern |
||||||
|
|
||||||
|
def preview |
||||||
|
texts, attachments, obj = parse_preview_data |
||||||
|
|
||||||
|
if obj.nil? || authorize_previewed_object(obj) |
||||||
|
render 'common/preview', |
||||||
|
layout: false, |
||||||
|
locals: { texts: texts, attachments: attachments, previewed: obj } |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
protected |
||||||
|
|
||||||
|
def parse_preview_data_helper(param_name, attributes, klass = nil) |
||||||
|
klass ||= param_name.to_s.classify.constantize |
||||||
|
|
||||||
|
texts = Array(attributes).each_with_object({}) do |attribute, list| |
||||||
|
caption = (attribute == :notes) ? Journal.human_attribute_name(:notes) |
||||||
|
: klass.human_attribute_name(attribute) |
||||||
|
text = params[param_name][attribute] |
||||||
|
list[caption] = text |
||||||
|
end |
||||||
|
|
||||||
|
obj = parse_previewed_object(klass) |
||||||
|
|
||||||
|
attachments = previewed_object_attachments(obj) |
||||||
|
|
||||||
|
return texts, attachments, obj |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def parse_previewed_object(klass) |
||||||
|
id = parse_previewed_id |
||||||
|
id ? klass.find_by_id(id) : nil |
||||||
|
end |
||||||
|
|
||||||
|
def parse_previewed_id |
||||||
|
params[:id] |
||||||
|
end |
||||||
|
|
||||||
|
def authorize_previewed_object(obj) |
||||||
|
@project = obj.project |
||||||
|
authorize |
||||||
|
end |
||||||
|
|
||||||
|
def previewed_object_attachments(obj) |
||||||
|
is_attachable = obj && (obj.respond_to?('attachable') || obj.respond_to?('attachments')) |
||||||
|
|
||||||
|
is_attachable ? obj.attachments : nil |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,36 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2014 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. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
require 'support/permission_specs' |
||||||
|
|
||||||
|
describe MessagesController, "add_messages permission", type: :controller do |
||||||
|
include PermissionSpecs |
||||||
|
|
||||||
|
check_permission_required_for('messages#preview', :add_messages) |
||||||
|
end |
@ -0,0 +1,36 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2014 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. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
require 'support/permission_specs' |
||||||
|
|
||||||
|
describe MessagesController, "edit_messages permission", type: :controller do |
||||||
|
include PermissionSpecs |
||||||
|
|
||||||
|
check_permission_required_for('messages#preview', :edit_messages) |
||||||
|
end |
@ -0,0 +1,36 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2014 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. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
require 'support/permission_specs' |
||||||
|
|
||||||
|
describe MessagesController, "edit_own_messages permission", type: :controller do |
||||||
|
include PermissionSpecs |
||||||
|
|
||||||
|
check_permission_required_for('messages#preview', :edit_own_messages) |
||||||
|
end |
@ -0,0 +1,36 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2014 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. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
require 'support/permission_specs' |
||||||
|
|
||||||
|
describe NewsController, "manage_news permission", type: :controller do |
||||||
|
include PermissionSpecs |
||||||
|
|
||||||
|
check_permission_required_for('news#preview', :manage_news) |
||||||
|
end |
@ -0,0 +1,78 @@ |
|||||||
|
#-- copyright |
||||||
|
# OpenProject is a project management system. |
||||||
|
# Copyright (C) 2012-2014 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. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
|
||||||
|
describe 'preview' do |
||||||
|
it "should connect POST /projects/:project_id/wiki/preview to wiki#preview" do |
||||||
|
post("/projects/1/wiki/preview").should route_to(controller: 'wiki', |
||||||
|
action: 'preview', |
||||||
|
project_id: '1') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST /projects/:project_id/wiki/:id/preview to wiki#preview" do |
||||||
|
post("/projects/1/wiki/1/preview").should route_to(controller: 'wiki', |
||||||
|
action: 'preview', |
||||||
|
project_id: '1', |
||||||
|
id: '1') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST news/preview to news#preview" do |
||||||
|
post("/news/preview").should route_to(controller: 'news', |
||||||
|
action: 'preview') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST /news/:id/preview to news#preview" do |
||||||
|
post("/news/1/preview").should route_to(controller: 'news', |
||||||
|
action: 'preview', |
||||||
|
id: '1') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST /boards/:board_id/topics/preview to messages#preview" do |
||||||
|
post("/boards/1/topics/preview").should route_to(controller: 'messages', |
||||||
|
action: 'preview', |
||||||
|
board_id: '1') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST /topics/:id/preview to messages#preview" do |
||||||
|
post("/topics/1/preview").should route_to(controller: 'messages', |
||||||
|
action: 'preview', |
||||||
|
id: '1') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST /work_packages/preview to work_packages#preview" do |
||||||
|
post("/work_packages/preview").should route_to(controller: 'work_packages', |
||||||
|
action: 'preview') |
||||||
|
end |
||||||
|
|
||||||
|
it "should connect POST /work_packages/:id/preview to work_packages#preview" do |
||||||
|
post("/work_packages/1/preview").should route_to(controller: 'work_packages', |
||||||
|
action: 'preview', |
||||||
|
id: '1') |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue