#48 The plugin option to see system folders replaced with a role permission

This commit is contained in:
Karel Picman 2017-05-16 10:24:52 +02:00
parent 7a4f7d998f
commit 57dcad1333
18 changed files with 51 additions and 45 deletions

View File

@ -711,14 +711,15 @@ class DmsfController < ApplicationController
@url_links = []
else
if @folder
@subfolders = @folder.dmsf_folders.visible
@subfolders = @folder.dmsf_folders.visible.to_a
@files = @folder.dmsf_files.visible
@dir_links = @folder.folder_links.visible
@file_links = @folder.file_links.visible
@url_links = @folder.url_links.visible
@locked_for_user = @folder.locked_for_user?
else
@subfolders = @project.dmsf_folders.visible
Rails.logger.info ">>> #{@project.dmsf_folders.visible.to_sql}"
@subfolders = @project.dmsf_folders.visible.to_a
@files = @project.dmsf_files.visible
@dir_links = @project.folder_links.visible
@file_links = @project.file_links.visible
@ -726,6 +727,20 @@ class DmsfController < ApplicationController
@locked_for_user = false
end
end
# Remove system folders you are not allowed to see because you are not allowed to see the issue
@subfolders.delete_if{ |folder|
if folder.system
issue_id = folder.title.to_i
if issue_id > 0
issue = Issue.find_by_id issue_id
issue && !issue.visible?(User.current)
else
false
end
else
false
end
}
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

@ -85,23 +85,35 @@ class DmsfFolder < ActiveRecord::Base
before_create :default_values
def self.visible_condition(system=true)
sql = Project.allowed_to_condition(User.current, :view_dmsf_folders) do |role, user|
Project.allowed_to_condition(User.current, :view_dmsf_folders) do |role, user|
if user.id && user.logged?
%{
(#{DmsfFolderPermission.table_name}.object_id IS NULL) OR
(#{DmsfFolderPermission.table_name}.object_id = #{role.id} AND #{DmsfFolderPermission.table_name}.object_type = 'Role') OR
(#{DmsfFolderPermission.table_name}.object_id = #{user.id} AND #{DmsfFolderPermission.table_name}.object_type = 'User')
((#{DmsfFolderPermission.table_name}.object_id IS NULL) OR
((#{DmsfFolderPermission.table_name}.object_id = #{role.id} AND #{DmsfFolderPermission.table_name}.object_type = 'Role')) OR
((#{DmsfFolderPermission.table_name}.object_id = #{user.id} AND #{DmsfFolderPermission.table_name}.object_type = 'User'))) AND
((#{DmsfFolder.table_name}.system = 0 OR 1 = #{(system && role.allowed_to?(:display_system_folders)) ? 1 : 0}))
}
else
'0 = 1'
end
end
"#{sql} AND (#{DmsfFolder.table_name}.system = 0 OR 1 = #{(system && Setting.plugin_redmine_dmsf['dmsf_show_system_folders']) ? 1 : 0})"
end
def self.permissions?(folder, allow_system = true)
return false if folder && folder.system && (!allow_system || !Setting.plugin_redmine_dmsf['dmsf_show_system_folders'])
# Administrator?
return true if (User.current.admin? || folder.nil?)
# System folder?
if folder && folder.system
if (!allow_system || !User.current.allowed_to?(:display_system_folders, folder.project))
return false
end
issue_id = folder.title.to_i
if issue_id > 0
issue = Issue.find_by_id issue_id
return false unless issue && issue.visible?(User.current)
end
end
# Permissions?
if !folder.dmsf_folder || permissions?(folder.dmsf_folder, allow_system)
if folder.dmsf_folder_permissions.any?
role_ids = User.current.roles_for_project(folder.project).map{ |r| r.id }

View File

@ -137,15 +137,6 @@
</em>
</p>
<p>
<%= content_tag(:label, l(:label_show_system_folders)) %>
<%= check_box_tag('settings[dmsf_show_system_folders]', true, @settings['dmsf_show_system_folders']) %>
<em class="info">
<%= l(:note_dmsf_show_system_folders) %><br/>
<%= l(:label_default)%>: <%= l(:general_text_No)%>
</em>
</p>
<hr/>
<em class="info">
<%= l(:menu_dmsf) %> <%= l(:field_column_names) %>

View File

@ -154,6 +154,7 @@ cs:
permission_force_file_unlock: Vynucené odemknutí souboru
permission_manage_workflows: Spravovat schvalovací procesy
permission_file_delete: Mazat dokumenty
permission_display_system_folders: Zobrazit systémové adresáře
label_file: Soubor
field_folder: Složka
error_create_cycle_in_folder_dependency: vytvořit smyčku v závislostech složky
@ -363,7 +364,5 @@ cs:
label_act_as_attachable: Jako příloha
note_dmsf_act_as_attachable: Umožní přikládat dokumenty k objektům např. úkolům.
label_show_system_folders: Zobrazit systémové složky
note_dmsf_show_system_folders: Systémové složky jsou složky se specifickým určením, např. pro dokumenty nahrané k úkolům.
label_user_search_add: Vyhledej uživatele pro přidání

View File

@ -154,6 +154,7 @@ de:
permission_force_file_unlock: Erzwinge Aufhebung der Dateisperre
permission_manage_workflows: Workflows verwalten
permission_file_delete: Datei löschen
permission_display_system_folders: Display system folders
label_file: Datei
field_folder: Ordner
error_create_cycle_in_folder_dependency: Zirkelabhängigkeit in der Ordnerstruktur erstellt
@ -360,7 +361,5 @@ de:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ en:
permission_force_file_unlock: Force file unlock
permission_manage_workflows: Manage workflows
permission_file_delete: Delete documents
permission_display_system_folders: Display system folders
label_file: File
field_folder: Folder
error_create_cycle_in_folder_dependency: create cycle in folder dependency
@ -363,7 +364,5 @@ en:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ es:
permission_force_file_unlock: Forzar desbloqueo de archivo
permission_manage_workflows: Gesti{on de flujo de trabajo
permission_file_delete: Eliminar documentos
permission_display_system_folders: Display system folders
label_file: Archivo
field_folder: Directorio
error_create_cycle_in_folder_dependency: crear ciclo en dependencia de directorio
@ -363,7 +364,5 @@ es:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ fr:
permission_force_file_unlock: Forcer le déverrouillage du document
permission_manage_workflows: Gérer les flux de validation
permission_file_delete: Supprimer les documents
permission_display_system_folders: Display system folders
label_file: Fichier
field_folder: Dossier
error_create_cycle_in_folder_dependency: Crée une dépendance cyclique du dossier
@ -363,7 +364,5 @@ fr:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -153,6 +153,7 @@ hu:
permission_force_file_unlock: Fájl kényszerített feloldása
permission_manage_workflows: Munkamenet kezelése
permission_file_delete: Dokumentumok törlése
permission_display_system_folders: Display system folders
label_file: Fájl
field_folder: Mappa
error_create_cycle_in_folder_dependency: hurok létrehozása a könyvtárstruktúrában
@ -362,7 +363,5 @@ hu:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ it: # Italian strings thx 2 Matteo Arceci!
permission_force_file_unlock: Forza lo sblocco del documento
permission_manage_workflows: Gestisci i flussi di lavoro
permission_file_delete: Elimina i documenti
permission_display_system_folders: Display system folders
label_file: Documento
field_folder: Cartella
error_create_cycle_in_folder_dependency: crea un ciclo nella dipendenza della cartella
@ -363,7 +364,5 @@ it: # Italian strings thx 2 Matteo Arceci!
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ ja:
permission_force_file_unlock: ファイルの強制ロック解除
permission_manage_workflows: ワークフロー管理
permission_file_delete: ファイルの削除
permission_display_system_folders: Display system folders
label_file: ファイル
field_folder: フォルダ
error_create_cycle_in_folder_dependency: フォルダの依存関係が循環しています
@ -363,7 +364,5 @@ ja:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ pl:
permission_force_file_unlock: Wymuś odblokowanie pliku
permission_manage_workflows: Zarządzaj procesami
permission_file_delete: Usuń dokumenty
permission_display_system_folders: Display system folders
label_file: Plik
field_folder: Folder
error_create_cycle_in_folder_dependency: utworzono pętlę zależności pomiędzy folderami
@ -363,7 +364,5 @@ pl:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ pt-BR:
permission_force_file_unlock: Force file unlock
permission_manage_workflows: Manage workflows
permission_file_delete: Delete documents
permission_display_system_folders: Display system folders
label_file: Arquivo
field_folder: Pasta
error_create_cycle_in_folder_dependency: Dependência entre pastas
@ -363,7 +364,5 @@ pt-BR:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ ru:
permission_force_file_unlock: Разблокировка любых файлов
permission_manage_workflows: Управление согласованиями
permission_file_delete: Удаление документов
permission_display_system_folders: Display system folders
label_file: Файл
field_folder: Папка
error_create_cycle_in_folder_dependency: создать циклическую зависимость в папке
@ -363,7 +364,5 @@ ru:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ sl:
permission_force_file_unlock: Prisilno odkleni datoteko
permission_manage_workflows: Manage workflows
permission_file_delete: Delete documents
permission_display_system_folders: Display system folders
label_file: Datoteka
field_folder: Pod mapo
error_create_cycle_in_folder_dependency: naredi ciklično odvisnost med mapami
@ -363,7 +364,5 @@ sl:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ zh-TW:
permission_force_file_unlock: 強制解除檔案鎖定
permission_manage_workflows: Manage workflows
permission_file_delete: Delete documents
permission_display_system_folders: Display system folders
label_file: 檔案
field_folder: 資料夾
error_create_cycle_in_folder_dependency: 資料夾之間的關係不得為一個cycle循環。
@ -363,7 +364,5 @@ zh-TW:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -154,6 +154,7 @@ zh:
permission_force_file_unlock: 强制文件解锁
permission_manage_workflows: Manage workflows
permission_file_delete: Delete documents
permission_display_system_folders: Display system folders
label_file: 文件
field_folder: 件夹
error_create_cycle_in_folder_dependency: create cycle in folder dependency
@ -363,7 +364,5 @@ zh:
label_act_as_attachable: Act as attachable
note_dmsf_act_as_attachable: Allows to attach documents to objects e.g. issues.
label_show_system_folders: Show system folders
note_dmsf_show_system_folders: System folders are folders with a specifics purpose, e.g. for documents attached to issues.
label_user_search_add: Search for user to add

View File

@ -99,6 +99,8 @@ Redmine::Plugin.register :redmine_dmsf do
permission :manage_workflows,
{ :dmsf_workflows => [:index, :new, :create, :destroy, :show, :new_step, :add_step, :remove_step, :reorder_steps,
:update, :update_step, :delete_step, :edit] }
permission :display_system_folders,
:read => true
end
# Administration menu extension