#48 Project's preferences

This commit is contained in:
Karel Picman 2017-05-26 15:37:35 +02:00
parent 1342033692
commit 84d971404c
8 changed files with 64 additions and 10 deletions

View File

@ -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

View File

@ -40,6 +40,9 @@ class DmsfStateController < ApplicationController
else
flash[:warning] = l(:user_is_not_project_member)
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

View File

@ -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?)) &&

View File

@ -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) }

View File

@ -26,7 +26,7 @@
<%= form_tag(dmsf_user_pref_save_path(@project)) do %>
<fieldset class="box tabular">
<legend><%= l(:link_user_preferences) %></legend>
<legend><%= l(:link_user_preferences) %></legend>
<p>
<%= content_tag(:label, "#{l(:label_notifications)}:") %>
<%= select_tag(
@ -41,5 +41,19 @@
<em class="info"><%= l(:text_title_format) %></em>
</p>
</fieldset>
<% if Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] %>
<fieldset class="box tabular">
<legend><%= l(:field_project) %> <%= l(:label_preferences) %></legend>
<p>
<%= 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)) %>
</p>
</fieldset>
<% end %>
<%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %>
<% end %>

View File

@ -0,0 +1,31 @@
# encoding: utf-8
#
# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011-17 Karel Pičman <karel.picman@kontron.com>
#
# 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

View File

@ -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 = "<div class=\"dmsf_uploader\">"
html << '<p>'
html << "<label>#{l(:label_document_plural)}</label>"
@ -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

View File

@ -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