You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

attachments_visibility_test.rb 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class AttachmentsVisibilityTest < Redmine::ControllerTest
  20. tests AttachmentsController
  21. fixtures :users, :email_addresses, :projects, :roles, :members, :member_roles,
  22. :enabled_modules, :projects_trackers, :issue_statuses, :enumerations,
  23. :issues, :trackers, :versions,
  24. :custom_fields, :custom_fields_trackers, :custom_fields_projects
  25. def setup
  26. User.current = nil
  27. set_tmp_attachments_directory
  28. @field = IssueCustomField.generate!(:field_format => 'attachment', :visible => true)
  29. @attachment = new_record(Attachment) do
  30. issue = Issue.generate
  31. issue.custom_field_values = {@field.id => {:file => mock_file}}
  32. issue.save!
  33. end
  34. end
  35. def test_attachment_should_be_visible
  36. @request.session[:user_id] = 2 # manager
  37. get :show, :params => {:id => @attachment.id}
  38. assert_response :success
  39. @field.update!(:visible => false, :role_ids => [1])
  40. get :show, :params => {:id => @attachment.id}
  41. assert_response :success
  42. end
  43. def test_attachment_should_be_visible_with_permission
  44. @request.session[:user_id] = 3 # developer
  45. get :show, :params => {:id => @attachment.id}
  46. assert_response :success
  47. @field.update!(:visible => false, :role_ids => [1])
  48. get :show, :params => {:id => @attachment.id}
  49. assert_response 403
  50. end
  51. end