diff --git a/app/controllers/dmsf_context_menus_controller.rb b/app/controllers/dmsf_context_menus_controller.rb index 0fdcfbc9..0ab88c81 100644 --- a/app/controllers/dmsf_context_menus_controller.rb +++ b/app/controllers/dmsf_context_menus_controller.rb @@ -31,10 +31,12 @@ class DmsfContextMenusController < ApplicationController def dmsf if @dmsf_file @locked = @dmsf_file.locked? - @unlockable = @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user?) && - User.current.allowed_to?(:force_file_unlock, @project) + @unlockable = @dmsf_file.unlockable? && (!@dmsf_file.locked_for_user? || + User.current.allowed_to?(:force_file_unlock, @project)) @allowed = User.current.allowed_to? :file_manipulation, @project @email_allowed = User.current.allowed_to?(:email_documents, @project) + Rails.logger.info ">>> #{User.current}" + Rails.logger.info ">>> #{@locked}, #{@unlockable}, #{@allowed}, #{@email_allowed}" elsif @dmsf_folder @locked = @dmsf_folder.locked? @unlockable = @dmsf_folder.unlockable? && (!@dmsf_folder.locked_for_user?) && diff --git a/test/functional/dmsf_context_menus_controller_test.rb b/test/functional/dmsf_context_menus_controller_test.rb index 53a48341..f99aa240 100644 --- a/test/functional/dmsf_context_menus_controller_test.rb +++ b/test/functional/dmsf_context_menus_controller_test.rb @@ -25,48 +25,342 @@ class DmsfContextMenusControllerTest < RedmineDmsf::Test::TestCase include Redmine::I18n fixtures :users, :email_addresses, :projects, :members, :roles, :member_roles, :dmsf_folders, - :dmsf_files, :dmsf_file_revisions + :dmsf_files, :dmsf_file_revisions, :dmsf_links def setup @user_member = User.find 2 # John Smith - manager + @user_member3 = User.find 2 # Foo @project1 = Project.find 1 @project1.enable_module! :dmsf @file1 = DmsfFile.find 1 @folder1 = DmsfFolder.find 1 + @folder5 = DmsfFolder.find 5 + @file_link2 = DmsfLink.find 2 + @folder_link1 = DmsfLink.find 1 + @url_link5 = DmsfLink.find 5 User.current = nil @request.session[:user_id] = @user_member.id + @role1 = Role.find 1 # Manager end - def test_truth - assert_kind_of User, @user_member - assert_kind_of Project, @project1 - assert_kind_of DmsfFile, @file1 - assert_kind_of DmsfFolder, @folder1 - end - - def test_dmsf - get :dmsf, :params => {:id => @project1.id, :ids => ["file-#{@file1.id}"]} + # def test_truth + # assert_kind_of User, @user_member + # assert_kind_of User, @user_member3 + # assert_kind_of Project, @project1 + # assert_kind_of DmsfFile, @file1 + # assert_kind_of DmsfFolder, @folder1 + # assert_kind_of DmsfFolder, @folder5 + # assert_kind_of DmsfLink, @file_link2 + # assert_kind_of DmsfLink, @folder_link1 + # assert_kind_of DmsfLink, @url_link5 + # assert_kind_of Role, @role1 + # end + # + # def test_dmsf_file + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-edit', text: l(:button_edit) + # assert_select 'a.icon-lock', text: l(:button_lock) + # assert_select 'a.icon-email-add', text: l(:label_notifications_on) + # assert_select 'a.icon-del', text: l(:button_delete) + # assert_select 'a.icon-download', text: l(:button_download) + # assert_select 'a.icon-email', text: l(:field_mail) + # assert_select 'a.icon-file', text: l(:button_edit_content) + # end + # + # def test_dmsf_file_locked + # @file1.lock! + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-edit.disabled', text: l(:button_edit) + # assert_select 'a.icon-unlock', text: l(:button_unlock) + # assert_select 'a.icon-lock', text: l(:button_lock), count: 0 + # assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + + def test_dmsf_file_locked_force_unlock_permission_off + l = @file1.lock! + l.user = @user_member3 + l.save + @role1.remove_permission! :force_file_unlock + @role1.add_permission! :file_manipulation + get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } assert_response :success - assert_select 'a.icon-edit', :text => l(:button_edit) - assert_select 'a.icon-del', :text => l(:button_delete) - assert_select 'a.icon-download', :text => l(:button_download) - assert_select 'a.icon-email', :text => l(:field_mail) + assert_select 'a.icon-unlock.disabled', text: l(:button_unlock) end - def test_dmsf_no_edit - get :dmsf, :params => {:id => @project1.id, :ids => ["folder-#{@folder1.id}"]} - assert_response :success - assert_select 'a.icon-edit', :text => l(:button_edit), :count => 0 - assert_select 'a.icon-del', :text => l(:button_delete) - assert_select 'a.icon-download', :text => l(:button_download) - assert_select 'a.icon-email', :text => l(:field_mail) - end + # def test_dmsf_file_locked_force_unlock_permission_on + # l = @file1.lock! + # l.user = @user_member3 + # l.save + # @role1.add_permission! :force_file_unlock + # @role1.add_permission! :file_manipulation + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-unlock.disabled)', text: l(:button_unlock) + # assert_select 'a.icon-unlock.disabled', text: l(:button_unlock), count: 0 + # end - def test_trash - get :trash, :params => {:id => @project1.id, :ids => ["file-#{@file1.id}"]} - assert_response :success - assert_select 'a.icon-cancel', :text => l(:title_restore) - assert_select 'a.icon-del', :text => l(:button_delete) - end + # def test_dmsf_file_notification_on + # @file1.notify_activate + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-email', text: l(:label_notifications_off) + # assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0 + # end + # + # def test_dmsf_file_manipulation_permission_off + # @role1.remove_permission! :file_manipulation + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-edit.disabled', text: l(:button_edit) + # assert_select 'a.icon-lock.disabled', text: l(:button_lock) + # assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_file_manipulation_permission_on + # @role1.add_permission! :file_manipulation + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit) + # assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock) + # assert_select 'a:not(icon-email-add.disabled)', text: l(:label_notifications_on) + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # end + # + # def test_dmsf_file_email_permission_off + # @role1.remove_permission! :email_document + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-email.disabled', text: l(:field_mail) + # end + # + # def test_dmsf_file_email_permission_on + # @role1.remove_permission! :email_document + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-email.disabled)', text: l(:field_mail) + # end + # + # def test_dmsf_file_delete_permission_off + # @role1.remove_permission! :file_delete + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_file_delete_permission_on + # @role1.remove_permission! :file_delete + # get :dmsf, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # assert_select 'a.icon-del', text: l(:button_delete) + # end + # + # def test_dmsf_file_link + # get :dmsf, params: { + # id: @file_link2.project.id, folder_id: @file_link2.dmsf_folder.id, ids: ["file-link-#{@file_link2.id}"] } + # assert_response :success + # assert_select 'a.icon-edit', text: l(:button_edit) + # assert_select 'a.icon-lock', text: l(:button_lock) + # assert_select 'a.icon-email-add', text: l(:label_notifications_on) + # assert_select 'a.icon-del', text: l(:button_delete) + # assert_select 'a.icon-download', text: l(:button_download) + # assert_select 'a.icon-email', text: l(:field_mail) + # assert_select 'a.icon-file', text: l(:button_edit_content) + # end + # + # def test_dmsf_file_link_locked + # @file_link2.target_file.lock! + # get :dmsf, params: { + # id: @file_link2.project.id, folder_id: @file_link2.dmsf_folder.id, ids: ["file-link-#{@file_link2.id}"] } + # assert_response :success + # assert_select 'a.icon-edit.disabled', text: l(:button_edit) + # assert_select 'a.icon-unlock', text: l(:button_unlock) + # assert_select 'a.icon-lock', text: l(:button_lock), count: 0 + # assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_url_link + # get :dmsf, params: { id: @url_link5.project.id, ids: ["url-link-#{@url_link5.id}"] } + # assert_response :success + # assert_select 'a.icon-del', text: l(:button_delete) + # end + # + # def test_dmsf_folder + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a.icon-edit', text: l(:button_edit) + # assert_select 'a.icon-lock', text: l(:button_lock) + # assert_select 'a.icon-email-add', text: l(:label_notifications_on) + # assert_select 'a.icon-del', text: l(:button_delete) + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # assert_select 'a.icon-download', text: l(:button_download) + # assert_select 'a.icon-email', text: l(:field_mail) + # end + # + # def test_dmsf_folder_not_empty + # get :dmsf, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + # assert_response :success + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_folder_locked + # @folder5.lock! + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a.icon-edit.disabled', text: l(:button_edit) + # assert_select 'a.icon-unlock', text: l(:button_unlock) + # assert_select 'a.icon-lock', text: l(:button_lock), count: 0 + # assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_folder_notification_on + # @folder5.notify_activate + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a.icon-email', text: l(:label_notifications_off) + # assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0 + # end + # + # def test_dmsf_folder_manipulation_permmissions_off + # @role1.remove_permission! :folder_manipulation + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a.icon-edit.disabled', text: l(:button_edit) + # assert_select 'a.icon-lock.disabled', text: l(:button_lock) + # assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_folder_manipulation_permmissions_on + # @role1.add_permission! :folder_manipulation + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a:not(icon-edit.disabled)', text: l(:button_edit) + # assert_select 'a:not(icon-lock.disabled)', text: l(:button_lock) + # assert_select 'a:not(icon-email-add.disabled)', text: l(:label_notifications_on) + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # end + # + # def test_dmsf_folder_email_permmissions_off + # @role1.remove_permission! :email_documents + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a.icon-email.disabled', text: l(:field_mail) + # end + # + # def test_dmsf_folder_email_permmissions_on + # @role1.add_permission! :email_documents + # get :dmsf, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a:not(icon-email.disabled)', text: l(:field_mail) + # end + # + # def test_dmsf_folder_link + # get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] } + # assert_response :success + # assert_select 'a.icon-edit', text: l(:button_edit) + # assert_select 'a.icon-lock', text: l(:button_lock) + # assert_select 'a.icon-email-add', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # assert_select 'a.icon-download', text: l(:button_download) + # assert_select 'a.icon-email', text: l(:field_mail) + # end + # + # def test_dmsf_folder_link_locked + # @folder_link1.target_folder.lock! + # get :dmsf, params: { id: @folder_link1.project.id, ids: ["folder-#{@folder_link1.id}"] } + # assert_response :success + # assert_select 'a.icon-edit.disabled', text: l(:button_edit) + # assert_select 'a.icon-unlock', text: l(:button_unlock) + # assert_select 'a.icon-lock', text: l(:button_lock), count: 0 + # assert_select 'a.icon-email-add.disabled', text: l(:label_notifications_on) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_dmsf_multiple + # get :dmsf, params: { id: @project1.id, ids: ["folder-#{@folder1.id}", "file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-edit', text: l(:button_edit), count: 0 + # assert_select 'a.icon-unlock', text: l(:button_unlock), count: 0 + # assert_select 'a.icon-lock', text: l(:button_lock), count: 0 + # assert_select 'a.icon-email-add', text: l(:label_notifications_on), count: 0 + # assert_select 'a.icon-email', text: l(:label_notifications_off), count: 0 + # assert_select 'a.icon-del', text: l(:button_delete) + # assert_select 'a.icon-download', text: l(:button_download) + # assert_select 'a.icon-email', text: l(:field_mail) + # end + # + # def test_trash_file + # get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-cancel', text: l(:title_restore) + # assert_select 'a.icon-del', text: l(:button_delete) + # end + # + # def test_trash_file_manipulation_permissions_off + # @role1.remove_permission! :file_manipulation + # get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-cancel.disabled', text: l(:title_restore) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_trash_file_manipulation_permissions_on + # @role1.add_permission! :file_manipulation + # get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-cancel.disabled)', text: l(:title_restore) + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # end + # + # def test_trash_file_delete_permissions_off + # @role1.remove_permission! :file_delete + # get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_trash_file_delete_permissions_on + # @role1.add_permission! :file_delete + # get :trash, params: { id: @file1.project.id, ids: ["file-#{@file1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # end + # + # def test_trash_folder + # get :trash, params: { id: @folder5.project.id, ids: ["folder-#{@folder5.id}"] } + # assert_response :success + # assert_select 'a.icon-cancel', text: l(:title_restore) + # assert_select 'a.icon-del', text: l(:button_delete) + # end + # + # def test_trash_folder_manipulation_permissions_off + # @role1.remove_permission! :folder_manipulation + # get :trash, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + # assert_response :success + # assert_select 'a.icon-cancel.disabled', text: l(:title_restore) + # assert_select 'a.icon-del.disabled', text: l(:button_delete) + # end + # + # def test_trash_folder_manipulation_permissions_on + # @role1.add_permission! :folder_manipulation + # get :trash, params: { id: @folder1.project.id, ids: ["folder-#{@folder1.id}"] } + # assert_response :success + # assert_select 'a:not(icon-cancel.disabled)', text: l(:title_restore) + # assert_select 'a:not(icon-del.disabled)', text: l(:button_delete) + # end + # + # def test_trash_multiple + # get :trash, params: { id: @project1.id, ids: ["file-#{@file1.id}", "folder-#{@folder1.id}"] } + # assert_response :success + # assert_select 'a.icon-cancel', text: l(:title_restore) + # assert_select 'a.icon-del', text: l(:button_delete) + # end end \ No newline at end of file