Actualizado plugin Redmine Questions 1.0.0 light
This commit is contained in:
parent
27e60f8ec1
commit
5d7889f1c9
140 changed files with 5342 additions and 1430 deletions
28
plugins/redmine_questions/lib/acts_as_attachable_questions/init.rb
Executable file
28
plugins/redmine_questions/lib/acts_as_attachable_questions/init.rb
Executable file
|
@ -0,0 +1,28 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# $LOAD_PATH.unshift(File.dirname(__FILE__))
|
||||
# require "lib/acts_as_viewable"
|
||||
# $LOAD_PATH.shift
|
||||
|
||||
require File.dirname(__FILE__) + '/lib/acts_as_attachable_questions'
|
||||
|
||||
unless ActiveRecord::Base.included_modules.include?(Redmine::Acts::AttachableQuestions)
|
||||
ActiveRecord::Base.send(:include, Redmine::Acts::AttachableQuestions)
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module Redmine
|
||||
module Acts
|
||||
module AttachableQuestions
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def acts_as_attachable_questions(options = {})
|
||||
if ActiveRecord::VERSION::MAJOR >= 4
|
||||
has_many :attachments, lambda { order("#{Attachment.table_name}.created_on") }, options.merge(:as => :container,
|
||||
:dependent => :destroy)
|
||||
else
|
||||
has_many :attachments, options.merge(:as => :container,
|
||||
:order => "#{Attachment.table_name}.created_on",
|
||||
:dependent => :destroy)
|
||||
end
|
||||
|
||||
send :include, Redmine::Acts::AttachableQuestions::InstanceMethods
|
||||
before_save :attach_saved_attachments
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
end
|
||||
|
||||
def attachments_visible?(user = User.current)
|
||||
respond_to?(:visible?) ? visible?(user) : true
|
||||
end
|
||||
|
||||
def attachments_editable?(user = User.current)
|
||||
(respond_to?(:visible?) ? visible?(user) : true) &&
|
||||
(user.allowed_to?(:manage_sections, project, :global => true) ||
|
||||
user.allowed_to?(:add_questions, project, :global => true))
|
||||
end
|
||||
|
||||
def attachments_deletable?(user = User.current)
|
||||
(respond_to?(:visible?) ? visible?(user) : true) &&
|
||||
(user.allowed_to?(:delete_questions, project, :global => true) ||
|
||||
user.allowed_to?(:add_questions, project, :global => true))
|
||||
end
|
||||
|
||||
def saved_attachments
|
||||
@saved_attachments ||= []
|
||||
end
|
||||
|
||||
def unsaved_attachments
|
||||
@unsaved_attachments ||= []
|
||||
end
|
||||
|
||||
def save_attachments(attachments, author = User.current)
|
||||
attachments = attachments.values if attachments.is_a?(Hash)
|
||||
if attachments.is_a?(Array)
|
||||
attachments.each do |attachment|
|
||||
a = nil
|
||||
if file = attachment['file']
|
||||
next unless file.size > 0
|
||||
a = Attachment.create(:file => file, :author => author)
|
||||
elsif token = attachment['token']
|
||||
a = Attachment.find_by_token(token)
|
||||
next unless a
|
||||
a.filename = attachment['filename'] unless attachment['filename'].blank?
|
||||
a.content_type = attachment['content_type']
|
||||
end
|
||||
next unless a
|
||||
a.description = attachment['description'].to_s.strip
|
||||
if a.new_record?
|
||||
unsaved_attachments << a
|
||||
else
|
||||
saved_attachments << a
|
||||
end
|
||||
end
|
||||
end
|
||||
{ :files => saved_attachments, :unsaved => unsaved_attachments }
|
||||
end
|
||||
|
||||
def attach_saved_attachments
|
||||
saved_attachments.each do |attachment|
|
||||
attachments << attachment
|
||||
end
|
||||
end
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
module RedmineQuestions
|
||||
module Patches
|
||||
module ActsAsVotableVotePatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
attr_accessible :votable, :voter, :vote_scope
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless RedmineCrm::ActsAsVotable::Vote.included_modules.include?(RedmineQuestions::Patches::ActsAsVotableVotePatch)
|
||||
RedmineCrm::ActsAsVotable::Vote.send(:include, RedmineQuestions::Patches::ActsAsVotableVotePatch)
|
||||
end
|
|
@ -1,7 +1,32 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_dependency 'redmine_questions/hooks/views_layouts_hook'
|
||||
|
||||
# require_dependency 'redmine_questions/patches/boards_controller_patch'
|
||||
require_dependency 'redmine_questions/patches/message_patch'
|
||||
require_dependency 'redmine_questions/patches/user_patch'
|
||||
require_dependency 'redmine_questions/patches/messages_controller_patch'
|
||||
require_dependency 'acts_as_votable_vote_patch' if ActiveRecord::VERSION::MAJOR >= 4
|
||||
require_dependency 'redmine_questions/patches/project_patch'
|
||||
require_dependency 'redmine_questions/patches/notifiable_patch'
|
||||
require_dependency 'redmine_questions/patches/mailer_patch'
|
||||
require_dependency 'redmine_questions/patches/projects_helper_patch'
|
||||
require_dependency 'redmine_questions/patches/auto_completes_controller_patch'
|
||||
require_dependency 'redmine_questions/patches/comment_patch'
|
||||
|
||||
require_dependency 'acts_as_attachable_questions/init'
|
||||
|
||||
require 'redmine_questions/patches/compatibility/application_controller_patch' if Rails::VERSION::MAJOR < 4
|
||||
|
|
|
@ -1,9 +1,28 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Hooks
|
||||
class ViewsLayoutsHook < Redmine::Hook::ViewListener
|
||||
def view_layouts_base_html_head(context={})
|
||||
return stylesheet_link_tag(:questions, :plugin => 'redmine_questions')
|
||||
return stylesheet_link_tag(:redmine_questions, :plugin => 'redmine_questions')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_dependency 'auto_completes_controller'
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module AutoCompletesControllerPatch
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def questions_tags
|
||||
@names_only = params[:names]
|
||||
@questions_tags = []
|
||||
q = (params[:q] || params[:term]).to_s.strip
|
||||
scope = Question.tags_cloud(:name_like => q, :limit => params[:limit] || 10)
|
||||
@questions_tags = scope.to_a.sort! { |x, y| x.name <=> y.name }
|
||||
render :layout => false, :partial => 'questions_tags'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless AutoCompletesController.included_modules.include?(RedmineQuestions::Patches::AutoCompletesControllerPatch)
|
||||
AutoCompletesController.send(:include, RedmineQuestions::Patches::AutoCompletesControllerPatch)
|
||||
end
|
|
@ -1,21 +0,0 @@
|
|||
require_dependency 'boards_controller'
|
||||
require_dependency 'board'
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
|
||||
module BoardsControllerPatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.class_eval do
|
||||
helper :questions
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
unless MessagesController.included_modules.include?(RedmineQuestions::Patches::BoardsControllerPatch)
|
||||
MessagesController.send(:include, RedmineQuestions::Patches::BoardsControllerPatch)
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module CommentPatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.send(:include, InstanceMethods)
|
||||
base.class_eval do
|
||||
unloadable
|
||||
if method_defined?(:send_notification)
|
||||
alias_method :send_notification_without_questions, :send_notification
|
||||
alias_method :send_notification, :send_notification_with_questions
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
def send_notification_with_questions
|
||||
if [Question, QuestionsAnswer].include?(commented.class)
|
||||
if Setting.notified_events.include?('question_comment_added')
|
||||
Mailer.send('question_comment_added', self).deliver
|
||||
end
|
||||
else
|
||||
send_notification_without_questions
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Comment.included_modules.include?(RedmineQuestions::Patches::CommentPatch)
|
||||
Comment.send(:include, RedmineQuestions::Patches::CommentPatch)
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module ApplicationControllerPatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
class << self
|
||||
alias_method :before_action, :before_filter
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless ApplicationController.included_modules.include?(RedmineQuestions::Patches::ApplicationControllerPatch)
|
||||
ApplicationController.send(:include, RedmineQuestions::Patches::ApplicationControllerPatch)
|
||||
end
|
|
@ -0,0 +1,87 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module MailerPatch
|
||||
module InstanceMethods
|
||||
def question_comment_added(comment)
|
||||
question = comment.commented.is_a?(Question) ? comment.commented : comment.commented.question
|
||||
@question_url = url_for(:controller => 'questions', :action => 'show', :id => question.id)
|
||||
project_identifier = question.project.try(:identifier)
|
||||
redmine_headers 'Project' => project_identifier, 'Question-Id' => question.id
|
||||
message_id comment
|
||||
@author = comment.author
|
||||
@comment = comment
|
||||
@question = question
|
||||
project_prefix = [project_identifier, question.section_name, "q&a#{question.id}"].compact.join(' - ')
|
||||
recipients = question.watcher_recipients
|
||||
mail :to => recipients,
|
||||
:subject => "[#{project_prefix}] RE: #{question.subject}"
|
||||
end
|
||||
|
||||
def question_question_added(question)
|
||||
@question_url = url_for(:controller => 'questions', :action => 'show', :id => question.id)
|
||||
project_identifier = question.project.try(:identifier)
|
||||
redmine_headers 'Project' => project_identifier, 'Question-Id' => question.id
|
||||
message_id question
|
||||
@author = question.author
|
||||
@question = question
|
||||
recipients = question.notified_users
|
||||
cc = question.section.notified_watchers - recipients
|
||||
project_prefix = [project_identifier, question.section_name, "q&a#{question.id}"].compact.join(' - ')
|
||||
mail :to => recipients,
|
||||
:cc => cc,
|
||||
:subject => "[#{project_prefix}] #{question.subject}"
|
||||
end
|
||||
|
||||
def question_answer_added(answer)
|
||||
question = answer.question
|
||||
@question_url = url_for(:controller => 'questions', :action => 'show', :id => question.id)
|
||||
project_identifier = question.project.try(:identifier)
|
||||
redmine_headers 'Project' => project_identifier, 'Question-Id' => question.id
|
||||
message_id question
|
||||
recipients = question.notified_users
|
||||
watchers = (question.notified_watchers + question.section.notified_watchers).uniq
|
||||
watchers = watchers.map(&:mail) if watchers.first.respond_to?(:mail)
|
||||
cc = watchers - recipients
|
||||
|
||||
@author = answer.author
|
||||
@answer = answer
|
||||
@question = question
|
||||
project_prefix = [project_identifier, question.section_name, "q&a#{question.id}"].compact.join(' - ')
|
||||
mail :to => recipients,
|
||||
:cc => cc,
|
||||
:subject => "[#{project_prefix}] - answ##{answer.id} - RE: #{question.subject}"
|
||||
end
|
||||
end
|
||||
|
||||
def self.included(receiver)
|
||||
receiver.send :include, InstanceMethods
|
||||
receiver.class_eval do
|
||||
unloadable
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Mailer.included_modules.include?(RedmineQuestions::Patches::MailerPatch)
|
||||
Mailer.send(:include, RedmineQuestions::Patches::MailerPatch)
|
||||
end
|
|
@ -1,44 +0,0 @@
|
|||
module RedmineQuestions
|
||||
module Patches
|
||||
module MessagePatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
rcrm_acts_as_taggable
|
||||
rcrm_acts_as_votable
|
||||
rcrm_acts_as_viewed
|
||||
|
||||
safe_attributes 'tag_list',
|
||||
:if => lambda {|message, user|
|
||||
user.allowed_to?(:edit_messages_tags, message.project)
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def to_param
|
||||
"#{id}-#{ActiveSupport::Inflector.transliterate(subject).parameterize}"
|
||||
end
|
||||
|
||||
def like(user)
|
||||
liked_by(user)
|
||||
end
|
||||
|
||||
def dislike(user)
|
||||
unvote(:voter => user)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Message.included_modules.include?(RedmineQuestions::Patches::MessagePatch)
|
||||
Message.send(:include, RedmineQuestions::Patches::MessagePatch)
|
||||
end
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
module RedmineQuestions
|
||||
module Patches
|
||||
|
||||
module MessagesControllerPatch
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def view_message
|
||||
@message.view(request.env['HTTP_X_FORWARDED_FOR'] || request.remote_ip || request.remote_addr, User.current.logged? ? User.current : nil) unless @message.author == User.current
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def self.included(base) # :nodoc:
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
after_filter :view_message, :only => :show
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
unless MessagesController.included_modules.include?(RedmineQuestions::Patches::MessagesControllerPatch)
|
||||
MessagesController.send(:include, RedmineQuestions::Patches::MessagesControllerPatch)
|
||||
end
|
|
@ -0,0 +1,49 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module NotifiablePatch
|
||||
def self.included(base)
|
||||
base.extend(ClassMethods)
|
||||
base.class_eval do
|
||||
unloadable
|
||||
class << self
|
||||
alias_method :all_without_questions, :all
|
||||
alias_method :all, :all_with_questions
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def all_with_questions
|
||||
notifications = all_without_questions
|
||||
notifications << Redmine::Notifiable.new('question_added')
|
||||
notifications << Redmine::Notifiable.new('question_answer_added')
|
||||
notifications << Redmine::Notifiable.new('question_comment_added')
|
||||
notifications
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Redmine::Notifiable.included_modules.include?(RedmineQuestions::Patches::NotifiablePatch)
|
||||
Redmine::Notifiable.send(:include, RedmineQuestions::Patches::NotifiablePatch)
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module ProjectPatch
|
||||
def self.included(base) # :nodoc:
|
||||
base.class_eval do
|
||||
unloadable # Send unloadable so it will not be unloaded in development
|
||||
has_many :questions_sections, :dependent => :delete_all
|
||||
has_many :questions, :through => :questions_sections
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Project.included_modules.include?(RedmineQuestions::Patches::ProjectPatch)
|
||||
Project.send(:include, RedmineQuestions::Patches::ProjectPatch)
|
||||
end
|
|
@ -0,0 +1,56 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require_dependency 'queries_helper'
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module ProjectsHelperPatch
|
||||
def self.included(base)
|
||||
base.send(:include, InstanceMethods)
|
||||
|
||||
base.class_eval do
|
||||
unloadable
|
||||
alias_method :project_settings_tabs_without_questions, :project_settings_tabs
|
||||
alias_method :project_settings_tabs, :project_settings_tabs_with_questions
|
||||
end
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
# include ContactsHelper
|
||||
|
||||
def project_settings_tabs_with_questions
|
||||
tabs = project_settings_tabs_without_questions
|
||||
|
||||
tabs.push({ :name => 'questions',
|
||||
:action => :manage_sections,
|
||||
:partial => 'projects/questions_settings',
|
||||
:label => :label_questions }) if User.current.allowed_to?(:manage_sections, @project)
|
||||
tabs
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless ProjectsHelper.included_modules.include?(RedmineQuestions::Patches::ProjectsHelperPatch)
|
||||
ProjectsHelper.send(:include, RedmineQuestions::Patches::ProjectsHelperPatch)
|
||||
end
|
|
@ -1,3 +1,22 @@
|
|||
# This file is a part of Redmine Q&A (redmine_questions) plugin,
|
||||
# Q&A plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2018 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_questions 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 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_questions 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 redmine_questions. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module RedmineQuestions
|
||||
module Patches
|
||||
module UserPatch
|
||||
|
|
59
plugins/redmine_questions/lib/tasks/migrate_from_boards.rake
Normal file
59
plugins/redmine_questions/lib/tasks/migrate_from_boards.rake
Normal file
|
@ -0,0 +1,59 @@
|
|||
namespace :redmine do
|
||||
namespace :questions do
|
||||
desc <<-END_DESC
|
||||
Migrate forum board to questions section
|
||||
|
||||
rake redmine:questions:migrate_board_to_section RAILS_ENV="production" board_id="source forum board id" question_section_id="destination question section id" project_id="section project id (nil for global section)"
|
||||
|
||||
END_DESC
|
||||
|
||||
task :migrate_board_to_section => :environment do
|
||||
board_id = ENV['board_id']
|
||||
question_section_id = ENV['question_section_id']
|
||||
question_section_name = ENV['question_section_name']
|
||||
project_id = ENV['project_id']
|
||||
|
||||
if board_id.blank? && project_id.blank?
|
||||
puts 'RedmineQuestions: Params board_id or project_id should be present'
|
||||
exit
|
||||
end
|
||||
|
||||
project = Project.where(:identifier => project_id).first
|
||||
project.enable_module!(:questions) if project
|
||||
boards = [Board.where(:id => board_id).first].compact
|
||||
boards = project.boards if project && boards.blank?
|
||||
boards.each do |board|
|
||||
section = QuestionsSection.for_project(project).where(:id => question_section_id).first
|
||||
section ||= QuestionsSection.for_project(project).find_or_create_by(:name => question_section_name) if question_section_name
|
||||
section ||= QuestionsSection.for_project(project).find_or_create_by(:name => board.name)
|
||||
if section.nil? || board.nil?
|
||||
puts 'RedmineQuestions: Destination section does not found' unless section
|
||||
puts 'RedmineQuestions: Source board does not found' unless board
|
||||
exit
|
||||
end
|
||||
|
||||
board.topics.reverse.each do |topic|
|
||||
if section.questions.where(:subject => topic.subject).first.present?
|
||||
puts "Questions with subject #{topic.subject} already exists."
|
||||
next
|
||||
end
|
||||
|
||||
question_attrs = topic.attributes.slice('subject', 'content', 'author_id', 'locked').merge('project_id' => project.try(:id))
|
||||
migrated_question = section.questions.create(question_attrs)
|
||||
migrated_question.attachments = topic.attachments.map { |attachment| attachment.copy }
|
||||
|
||||
topic.children.each do |reply|
|
||||
if section.section_type == 'questions'
|
||||
answer_attrs = reply.slice('subject', 'content', 'author_id', 'locked').merge('project_id' => project.try(:id))
|
||||
migrated_answer = migrated_question.answers.create(answer_attrs)
|
||||
migrated_answer.attachments = reply.attachments.map { |attachment| attachment.copy }
|
||||
else
|
||||
comment_attrs = { 'author_id' => reply.author_id, 'comments' => reply.content }
|
||||
migrated_question.comments.create(comment_attrs)
|
||||
end
|
||||
end
|
||||
end
|
||||
end #each
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue