From 3d7a6a2ec146a1f2433db58ae83e5c7a449e6931 Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Mon, 10 Apr 2017 18:08:57 +0200 Subject: [PATCH] #170 visible condition fix --- app/controllers/dmsf_controller.rb | 3 +-- app/helpers/dmsf_folder_permissions_helper.rb | 3 ++- app/models/dmsf_folder.rb | 10 +++++----- app/views/dmsf/edit.html.erb | 2 +- config/locales/cs.yml | 2 ++ config/locales/de.yml | 2 ++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ config/locales/fr.yml | 2 ++ config/locales/it.yml | 2 ++ config/locales/ja.yml | 2 ++ config/locales/pl.yml | 2 ++ config/locales/pt-BR.yml | 2 ++ config/locales/ru.yml | 2 ++ config/locales/sl.yml | 2 ++ config/locales/zh-TW.yml | 2 ++ config/locales/zh.yml | 2 ++ 17 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index f27e76ce..bac2e280 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -38,6 +38,7 @@ class DmsfController < ApplicationController helper :dmsf_folder_permissions def permissions + Rails.logger.info ">>> #{DmsfFolder.visible.where(:project_id => @project.id).to_sql}" render_403 unless DmsfFolder.permissions(@folder) true end @@ -53,8 +54,6 @@ class DmsfController < ApplicationController end def show - s = DmsfFolder.visible.where(:project_id => 1995).to_sql - Rails.logger.info s # also try to lookup folder by title if this is API call find_folder_by_title if [:xml, :json].include? request.format.to_sym get_display_params diff --git a/app/helpers/dmsf_folder_permissions_helper.rb b/app/helpers/dmsf_folder_permissions_helper.rb index 4e0b6124..c6d3dfdf 100644 --- a/app/helpers/dmsf_folder_permissions_helper.rb +++ b/app/helpers/dmsf_folder_permissions_helper.rb @@ -7,12 +7,13 @@ module DmsfFolderPermissionsHelper content = check_box_tag('permissions[user_ids][]', user.id, true, :id => nil) + user.name s << content_tag(:label, content, :id => "user_permission_ids_#{user.id}", :class => 'inline') end + s << '
' if users.any? end s.html_safe end def render_principals_for_new_folder_permissions(users) - principals_check_box_tags 'user[user_ids][]', users + principals_check_box_tags 'user_ids[]', users end end diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index 83f7bc89..49e75586 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -52,11 +52,11 @@ class DmsfFolder < ActiveRecord::Base scope :visible, -> { joins(:project).joins( "LEFT JOIN #{DmsfFolderPermission.table_name} ON #{DmsfFolder.table_name}.id = #{DmsfFolderPermission.table_name}.dmsf_folder_id").where( - :deleted => STATUS_ACTIVE).where(DmsfFolder.visible_condition) + :deleted => STATUS_ACTIVE).where(DmsfFolder.visible_condition).distinct } scope :deleted, -> { joins(:project).joins( "LEFT JOIN #{DmsfFolderPermission.table_name} ON #{DmsfFolder.table_name}.id = #{DmsfFolderPermission.table_name}.dmsf_folder_id").where( - :deleted => STATUS_DELETED).where(DmsfFolder.visible_condition) + :deleted => STATUS_DELETED).where(DmsfFolder.visible_condition).distinct } acts_as_customizable @@ -84,17 +84,17 @@ class DmsfFolder < ActiveRecord::Base before_create :default_values def self.visible_condition - sql = '1=1' Project.allowed_to_condition(User.current, :view_dmsf_folders) do |role, user| if user.id && user.logged? - sql = %{ + %{ (#{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') } + else + '0=1' end end - sql end def self.permissions(folder) diff --git a/app/views/dmsf/edit.html.erb b/app/views/dmsf/edit.html.erb index bee295a3..efcb47f9 100644 --- a/app/views/dmsf/edit.html.erb +++ b/app/views/dmsf/edit.html.erb @@ -92,7 +92,7 @@ <%= users_checkboxes(@users) %> - <%= link_to l(:label_user_search), + <%= link_to l(:label_user_search_add), new_dmsf_folder_permissions_path(:project_id => @project, :dmsf_folder_id => @folder), :remote => true, :method => 'get' %> diff --git a/config/locales/cs.yml b/config/locales/cs.yml index 062cdf59..391e051a 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -364,3 +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_user_search_add: Vyhledej uživatele pro přidání \ No newline at end of file diff --git a/config/locales/de.yml b/config/locales/de.yml index d6a30f2b..2e29b144 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -361,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 8a3c360b..4c9d3824 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -364,3 +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_user_search_add: Search for user to add diff --git a/config/locales/es.yml b/config/locales/es.yml index 988a94e8..8eec69d4 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a6fc3e94..18c0f62d 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/it.yml b/config/locales/it.yml index ed632299..e21cc184 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/ja.yml b/config/locales/ja.yml index d7d8924e..bc8527ab 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 7fd3cfe9..c75980e2 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 26488b8c..5ae96e85 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 6d8d3e09..85bf836f 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 4e20512c..be625336 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index 2e84de4c..dc4106ed 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 16fe81b2..92855ef2 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -364,3 +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_user_search_add: Search for user to add \ No newline at end of file