From 84d971404c67b4f647f5c7e3b12a4500265e0834 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Fri, 26 May 2017 15:37:35 +0200 Subject: [PATCH] #48 Project's preferences --- app/controllers/dmsf_controller.rb | 2 +- app/controllers/dmsf_state_controller.rb | 5 ++- app/helpers/dmsf_helper.rb | 7 +++-- app/models/dmsf_file.rb | 4 +-- app/views/dmsf_state/_user_pref.html.erb | 16 +++++++++- db/migrate/20170526144701_dmsf_attachable.rb | 31 +++++++++++++++++++ .../hooks/views/issue_view_hooks.rb | 6 ++-- lib/redmine_dmsf/patches/project_patch.rb | 3 ++ 8 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 db/migrate/20170526144701_dmsf_attachable.rb diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 794288a1..c07d4430 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -729,7 +729,7 @@ class DmsfController < ApplicationController end end # Remove system folders you are not allowed to see because you are not allowed to see the issue - @subfolders = DmsfHelper.visible_folders(@subfolders) + @subfolders = DmsfHelper.visible_folders(@subfolders, @project) end @ajax_upload_size = Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'].present? ? Setting.plugin_redmine_dmsf['dmsf_max_ajax_upload_filesize'] : 100 diff --git a/app/controllers/dmsf_state_controller.rb b/app/controllers/dmsf_state_controller.rb index 18cb263c..642f7aae 100644 --- a/app/controllers/dmsf_state_controller.rb +++ b/app/controllers/dmsf_state_controller.rb @@ -39,7 +39,10 @@ class DmsfStateController < ApplicationController end else flash[:warning] = l(:user_is_not_project_member) - end + end + if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] + @project.update_attribute :dmsf_act_as_attachable, params[:act_as_attachable] + end redirect_to settings_project_path(@project, :tab => 'dmsf') end diff --git a/app/helpers/dmsf_helper.rb b/app/helpers/dmsf_helper.rb index 844b3593..32cfecf4 100644 --- a/app/helpers/dmsf_helper.rb +++ b/app/helpers/dmsf_helper.rb @@ -89,8 +89,9 @@ module DmsfHelper 'plupload/js/i18n/en.js' end - def self.visible_folders(folders) - allowed = Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] + def self.visible_folders(folders, project) + allowed = Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + (project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) folders.reject{ |folder| if folder.system unless allowed @@ -112,7 +113,7 @@ module DmsfHelper def self.all_children_sorted(parent, pos, ident) # Folders && files && links - nodes = visible_folders(parent.dmsf_folders.visible.to_a) + parent.dmsf_links.visible + parent.dmsf_files.visible + nodes = visible_folders(parent.dmsf_folders.visible.to_a, parent.is_a?(Project) ? parent : parent.project) + parent.dmsf_links.visible + parent.dmsf_files.visible # Alphabetical and type sort nodes.sort! do |x, y| if ((x.is_a?(DmsfFolder) || (x.is_a?(DmsfLink) && x.is_folder?)) && diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 5499e7d5..f12d4954 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -44,8 +44,8 @@ class DmsfFile < ActiveRecord::Base :class_name => 'DmsfLink', :foreign_key => 'target_id', :dependent => :destroy has_many :dmsf_public_urls, :dependent => :destroy - STATUS_DELETED = 1 - STATUS_ACTIVE = 0 + STATUS_DELETED = 1.freeze + STATUS_ACTIVE = 0.freeze scope :visible, -> { where(:deleted => STATUS_ACTIVE) } scope :deleted, -> { where(:deleted => STATUS_DELETED) } diff --git a/app/views/dmsf_state/_user_pref.html.erb b/app/views/dmsf_state/_user_pref.html.erb index b74af4b0..af329250 100644 --- a/app/views/dmsf_state/_user_pref.html.erb +++ b/app/views/dmsf_state/_user_pref.html.erb @@ -26,7 +26,7 @@ <%= form_tag(dmsf_user_pref_save_path(@project)) do %>
- <%= l(:link_user_preferences) %> + <%= l(:link_user_preferences) %>

<%= content_tag(:label, "#{l(:label_notifications)}:") %> <%= select_tag( @@ -41,5 +41,19 @@ <%= l(:text_title_format) %>

+ <% if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] %> +
+ <%= l(:field_project) %> <%= l(:label_preferences) %> +

+ <%= content_tag(:label, "#{l(:label_act_as_attachable)}:") %> + <%= select_tag( + 'act_as_attachable', + options_for_select([ + [l(:label_attachment_plural) + ' & ' + l(:menu_dmsf), Project::ATTACHABLE_DMS_AND_ATTACHMENTS], + [l(:label_attachment_plural), Project::ATTACHABLE_ATTACHMENTS], + ],:selected => @project.dmsf_act_as_attachable)) %> +

+
+ <% end %> <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> <% end %> \ No newline at end of file diff --git a/db/migrate/20170526144701_dmsf_attachable.rb b/db/migrate/20170526144701_dmsf_attachable.rb new file mode 100644 index 00000000..d35d3a42 --- /dev/null +++ b/db/migrate/20170526144701_dmsf_attachable.rb @@ -0,0 +1,31 @@ +# encoding: utf-8 +# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011-17 Karel Pičman +# +# 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. + +class DmsfAttachable < ActiveRecord::Migration + def self.up + # DMSF - project's root folder notification + add_column :projects, :dmsf_act_as_attachable, :integer, :default => 1, :null => false + Project.update_all dmsf_act_as_attachable: 1 + end + + def self.down + remove_column :projects, :dmsf_act_as_attachable + end +end \ No newline at end of file diff --git a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb index a65a1c86..13604b06 100644 --- a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb @@ -29,7 +29,8 @@ module RedmineDmsf # Add Dmsf upload form issue = context[:issue] if User.current.allowed_to?(:file_manipulation, issue.project) && - Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] + Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + (issue.project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) html = "
" html << '

' html << "" @@ -47,7 +48,8 @@ module RedmineDmsf # Add list of attached documents issue = context[:issue] if User.current.allowed_to?(:view_dmsf_files, issue.project) && - Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] + Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + (issue.project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) links = [] for dmsf_file in issue.dmsf_files if dmsf_file.last_revision diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 77318b21..841efad8 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -48,6 +48,9 @@ module RedmineDmsf before_save :set_default_dmsf_notification validates_length_of :dmsf_description, :maximum => 65535 + + Project.const_set(:ATTACHABLE_DMS_AND_ATTACHMENTS, 1) + Project.const_set(:ATTACHABLE_ATTACHMENTS, 2) end end