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.2KB

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