2019-03-16 15:03:47 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2018-01-08 17:43:31 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2018-01-08 17:43:31 +00:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
2023-01-01 07:13:39 +00:00
|
|
|
require_relative '../test_helper'
|
2018-01-08 17:43:31 +00:00
|
|
|
|
|
|
|
|
class AttachmentsVisibilityTest < Redmine::ControllerTest
|
|
|
|
|
tests AttachmentsController
|
|
|
|
|
def setup
|
2018-11-03 07:15:00 +00:00
|
|
|
User.current = nil
|
2018-01-08 17:43:31 +00:00
|
|
|
set_tmp_attachments_directory
|
|
|
|
|
|
|
|
|
|
@field = IssueCustomField.generate!(:field_format => 'attachment', :visible => true)
|
|
|
|
|
@attachment = new_record(Attachment) do
|
|
|
|
|
issue = Issue.generate
|
|
|
|
|
issue.custom_field_values = {@field.id => {:file => mock_file}}
|
|
|
|
|
issue.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_attachment_should_be_visible
|
|
|
|
|
@request.session[:user_id] = 2 # manager
|
|
|
|
|
get :show, :params => {:id => @attachment.id}
|
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
@field.update!(:visible => false, :role_ids => [1])
|
|
|
|
|
get :show, :params => {:id => @attachment.id}
|
|
|
|
|
assert_response :success
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_attachment_should_be_visible_with_permission
|
|
|
|
|
@request.session[:user_id] = 3 # developer
|
|
|
|
|
get :show, :params => {:id => @attachment.id}
|
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
@field.update!(:visible => false, :role_ids => [1])
|
|
|
|
|
get :show, :params => {:id => @attachment.id}
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :forbidden
|
2018-01-08 17:43:31 +00:00
|
|
|
end
|
|
|
|
|
end
|