From b05a438bea1b28ca6971ffdaf3ab7b445f8feb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Pi=C4=8Dman?= Date: Tue, 9 Aug 2022 14:11:14 +0200 Subject: [PATCH] Version of revision in wiki #1390 --- lib/redmine_dmsf/macros.rb | 22 ++++++++++++++----- test/fixtures/dmsf_file_revisions.yml | 2 +- .../webdav/dmsf_webdav_put_test.rb | 2 +- .../unit/lib/redmine_dmsf/dmsf_macros_test.rb | 8 ++++++- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/redmine_dmsf/macros.rb b/lib/redmine_dmsf/macros.rb index b40fcbb4..05320e67 100644 --- a/lib/redmine_dmsf/macros.rb +++ b/lib/redmine_dmsf/macros.rb @@ -32,11 +32,14 @@ module RedmineDmsf macro :dmsf do |obj, args| raise ArgumentError if args.length < 1 # Requires file id file = DmsfFile.visible.find args[0] + unless User.current&.allowed_to?(:view_dmsf_files, file.project, { id: file.id }) + raise l(:notice_not_authorized) + end if args[2].blank? revision = file.last_revision else - revision = DmsfFileRevision.find args[2] - if revision.dmsf_file != file + revision = DmsfFileRevision.find_by(id: args[2], dmsf_file_id: args[0]) + unless revision raise ActiveRecord::RecordNotFound end end @@ -110,16 +113,23 @@ module RedmineDmsf # dmsfversion - text referring to the document's version desc "Text referring to DMSF document version:\n\n" + - "{{dmsfversion(document_id)}}\n\n" + + "{{dmsfversion(document_id [, revision_id])}}\n\n" + "_document_id_ can be found in the document's details." macro :dmsfversion do |obj, args| raise ArgumentError if args.length < 1 # Requires file id file = DmsfFile.visible.find args[0] - if User.current&.allowed_to?(:view_dmsf_files, file.project) - textilizable file.version - else + unless User.current&.allowed_to?(:view_dmsf_files, file.project, { id: file.id }) raise l(:notice_not_authorized) end + if args[1].blank? + revision = file.last_revision + else + revision = DmsfFileRevision.find_by(id: args[1], dmsf_file_id: args[0]) + unless revision + raise ActiveRecord::RecordNotFound + end + end + textilizable revision.version end # dmsflastupdate - text referring to the document's last update date diff --git a/test/fixtures/dmsf_file_revisions.yml b/test/fixtures/dmsf_file_revisions.yml index a2acec65..19680140 100644 --- a/test/fixtures/dmsf_file_revisions.yml +++ b/test/fixtures/dmsf_file_revisions.yml @@ -97,7 +97,7 @@ dmsf_file_revisions_005: title: 'Test File' description: NULL workflow: 1 # DmsfWorkflow::STATE_WAITING_FOR_APPROVAL - minor_version: 0 + minor_version: 1 major_version: 1 comment: 'Wrong mime type in order to have Edit content menu item' deleted: 0 diff --git a/test/integration/webdav/dmsf_webdav_put_test.rb b/test/integration/webdav/dmsf_webdav_put_test.rb index 547454a2..bab4524d 100644 --- a/test/integration/webdav/dmsf_webdav_put_test.rb +++ b/test/integration/webdav/dmsf_webdav_put_test.rb @@ -355,7 +355,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest headers: @jsmith.merge!({ content_type: :text }) assert_response :created end - assert_equal '1.1', @file1.last_revision.version + assert_equal '1.2', @file1.last_revision.version end end \ No newline at end of file diff --git a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb index 073c4d0a..4e56be7d 100644 --- a/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb +++ b/test/unit/lib/redmine_dmsf/dmsf_macros_test.rb @@ -163,12 +163,18 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest assert_not_equal "

#{@file1.description}

", text end - # {{dmsfversion(document_id)}} + # {{dmsfversion(document_id [, revision_id])}} def test_macro_dmsfdversion text = textilizable("{{dmsfversion(#{@file1.id})}}") assert_equal "

#{@file1.version}

", text end + def test_macro_dmsfdversion + revision5 = DmsfFileRevision.find_by(id: 5) + text = textilizable("{{dmsfversion(#{@file1.id}, #{revision5.id})}}") + assert_equal "

#{revision5.version}

", text + end + def test_macro_dmsfdversion_no_permissions @manager_role.remove_permission! :view_dmsf_files text = textilizable("{{dmsfversion(#{@file1.id})}}")