2019-03-17 00:29:58 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-02-27 13:34:41 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2008-02-02 10:50:31 +00:00
|
|
|
#
|
|
|
|
|
# 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.
|
2011-08-31 10:10:33 +00:00
|
|
|
#
|
2008-02-02 10:50:31 +00:00
|
|
|
# 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.
|
2011-08-31 10:10:33 +00:00
|
|
|
#
|
2008-02-02 10:50:31 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
class JournalsController < ApplicationController
|
2016-07-14 07:27:31 +00:00
|
|
|
before_action :find_journal, :only => [:edit, :update, :diff]
|
|
|
|
|
before_action :find_issue, :only => [:new]
|
|
|
|
|
before_action :find_optional_project, :only => [:index]
|
|
|
|
|
before_action :authorize, :only => [:new, :edit, :update, :diff]
|
2022-03-19 09:56:46 +00:00
|
|
|
accept_atom_auth :index
|
2022-03-23 14:26:47 +00:00
|
|
|
accept_api_auth :update
|
2011-02-27 13:34:41 +00:00
|
|
|
menu_item :issues
|
2011-08-31 10:10:33 +00:00
|
|
|
|
2010-08-23 15:04:36 +00:00
|
|
|
helper :issues
|
2011-03-06 16:04:35 +00:00
|
|
|
helper :custom_fields
|
2010-08-23 15:04:36 +00:00
|
|
|
helper :queries
|
2021-11-22 08:42:44 +00:00
|
|
|
helper :attachments
|
2010-08-23 15:04:36 +00:00
|
|
|
include QueriesHelper
|
2024-10-09 21:51:52 +00:00
|
|
|
include Redmine::QuoteReply::Builder
|
2010-08-23 15:04:36 +00:00
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
retrieve_query
|
|
|
|
|
if @query.valid?
|
2011-08-31 10:10:33 +00:00
|
|
|
@journals = @query.journals(:order => "#{Journal.table_name}.created_on DESC",
|
2010-08-23 15:04:36 +00:00
|
|
|
:limit => 25)
|
|
|
|
|
end
|
|
|
|
|
@title = (@project ? @project.name : Setting.app_title) + ": " + (@query.new_record? ? l(:label_changes_details) : @query.name)
|
|
|
|
|
render :layout => false, :content_type => 'application/atom+xml'
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
render_404
|
|
|
|
|
end
|
2011-08-31 10:10:33 +00:00
|
|
|
|
2011-02-27 13:34:41 +00:00
|
|
|
def diff
|
|
|
|
|
@issue = @journal.issue
|
|
|
|
|
if params[:detail_id].present?
|
|
|
|
|
@detail = @journal.details.find_by_id(params[:detail_id])
|
|
|
|
|
else
|
2015-01-31 10:42:41 +00:00
|
|
|
@detail = @journal.details.detect {|d| d.property == 'attr' && d.prop_key == 'description'}
|
|
|
|
|
end
|
|
|
|
|
unless @issue && @detail
|
|
|
|
|
render_404
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
if @detail.property == 'cf'
|
|
|
|
|
unless @detail.custom_field && @detail.custom_field.visible_by?(@issue.project, User.current)
|
|
|
|
|
raise ::Unauthorized
|
|
|
|
|
end
|
2011-02-27 13:34:41 +00:00
|
|
|
end
|
|
|
|
|
@diff = Redmine::Helpers::Diff.new(@detail.value, @detail.old_value)
|
|
|
|
|
end
|
2011-08-31 10:10:33 +00:00
|
|
|
|
2010-08-16 16:25:04 +00:00
|
|
|
def new
|
2012-10-03 21:36:19 +00:00
|
|
|
@journal = Journal.visible.find(params[:journal_id]) if params[:journal_id]
|
2024-10-09 21:51:52 +00:00
|
|
|
@content = if @journal
|
|
|
|
|
quote_issue_journal(@journal, indice: params[:journal_indice], partial_quote: params[:quote])
|
|
|
|
|
else
|
|
|
|
|
quote_issue(@issue, partial_quote: params[:quote])
|
|
|
|
|
end
|
2012-10-03 21:36:19 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
render_404
|
2010-08-16 16:25:04 +00:00
|
|
|
end
|
2011-08-31 10:10:33 +00:00
|
|
|
|
2008-02-02 10:50:31 +00:00
|
|
|
def edit
|
2011-02-27 13:34:41 +00:00
|
|
|
(render_403; return false) unless @journal.editable_by?(User.current)
|
2016-01-21 04:39:56 +00:00
|
|
|
respond_to do |format|
|
|
|
|
|
# TODO: implement non-JS journal update
|
|
|
|
|
format.js
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
(render_403; return false) unless @journal.editable_by?(User.current)
|
2022-07-17 04:40:01 +00:00
|
|
|
journal_attributes = params[:journal]
|
|
|
|
|
journal_attributes[:updated_by] = User.current
|
|
|
|
|
@journal.safe_attributes = journal_attributes
|
2016-07-10 10:58:00 +00:00
|
|
|
@journal.save
|
2016-01-21 04:39:56 +00:00
|
|
|
@journal.destroy if @journal.details.empty? && @journal.notes.blank?
|
2020-11-14 13:17:54 +00:00
|
|
|
call_hook(:controller_journals_edit_post, {:journal => @journal, :params => params})
|
2016-01-21 04:39:56 +00:00
|
|
|
respond_to do |format|
|
2020-11-14 13:17:54 +00:00
|
|
|
format.html {redirect_to issue_path(@journal.journalized)}
|
2016-01-21 04:39:56 +00:00
|
|
|
format.js
|
2022-03-23 14:26:47 +00:00
|
|
|
format.api { render_api_ok }
|
2008-02-02 10:50:31 +00:00
|
|
|
end
|
|
|
|
|
end
|
2011-08-31 10:10:33 +00:00
|
|
|
|
2011-02-27 13:34:41 +00:00
|
|
|
private
|
2011-08-31 10:10:33 +00:00
|
|
|
|
2008-02-02 10:50:31 +00:00
|
|
|
def find_journal
|
2012-10-03 21:36:19 +00:00
|
|
|
@journal = Journal.visible.find(params[:id])
|
2008-02-12 18:31:15 +00:00
|
|
|
@project = @journal.journalized.project
|
2008-02-02 10:50:31 +00:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
render_404
|
|
|
|
|
end
|
|
|
|
|
end
|