Version of revision in wiki #1390
This commit is contained in:
parent
e9a2bb000b
commit
b05a438bea
@ -32,11 +32,14 @@ module RedmineDmsf
|
|||||||
macro :dmsf do |obj, args|
|
macro :dmsf do |obj, args|
|
||||||
raise ArgumentError if args.length < 1 # Requires file id
|
raise ArgumentError if args.length < 1 # Requires file id
|
||||||
file = DmsfFile.visible.find args[0]
|
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?
|
if args[2].blank?
|
||||||
revision = file.last_revision
|
revision = file.last_revision
|
||||||
else
|
else
|
||||||
revision = DmsfFileRevision.find args[2]
|
revision = DmsfFileRevision.find_by(id: args[2], dmsf_file_id: args[0])
|
||||||
if revision.dmsf_file != file
|
unless revision
|
||||||
raise ActiveRecord::RecordNotFound
|
raise ActiveRecord::RecordNotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -110,16 +113,23 @@ module RedmineDmsf
|
|||||||
|
|
||||||
# dmsfversion - text referring to the document's version
|
# dmsfversion - text referring to the document's version
|
||||||
desc "Text referring to DMSF document version:\n\n" +
|
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."
|
"_document_id_ can be found in the document's details."
|
||||||
macro :dmsfversion do |obj, args|
|
macro :dmsfversion do |obj, args|
|
||||||
raise ArgumentError if args.length < 1 # Requires file id
|
raise ArgumentError if args.length < 1 # Requires file id
|
||||||
file = DmsfFile.visible.find args[0]
|
file = DmsfFile.visible.find args[0]
|
||||||
if User.current&.allowed_to?(:view_dmsf_files, file.project)
|
unless User.current&.allowed_to?(:view_dmsf_files, file.project, { id: file.id })
|
||||||
textilizable file.version
|
|
||||||
else
|
|
||||||
raise l(:notice_not_authorized)
|
raise l(:notice_not_authorized)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# dmsflastupdate - text referring to the document's last update date
|
# dmsflastupdate - text referring to the document's last update date
|
||||||
|
|||||||
2
test/fixtures/dmsf_file_revisions.yml
vendored
2
test/fixtures/dmsf_file_revisions.yml
vendored
@ -97,7 +97,7 @@ dmsf_file_revisions_005:
|
|||||||
title: 'Test File'
|
title: 'Test File'
|
||||||
description: NULL
|
description: NULL
|
||||||
workflow: 1 # DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
workflow: 1 # DmsfWorkflow::STATE_WAITING_FOR_APPROVAL
|
||||||
minor_version: 0
|
minor_version: 1
|
||||||
major_version: 1
|
major_version: 1
|
||||||
comment: 'Wrong mime type in order to have Edit content menu item'
|
comment: 'Wrong mime type in order to have Edit content menu item'
|
||||||
deleted: 0
|
deleted: 0
|
||||||
|
|||||||
@ -355,7 +355,7 @@ class DmsfWebdavPutTest < RedmineDmsf::Test::IntegrationTest
|
|||||||
headers: @jsmith.merge!({ content_type: :text })
|
headers: @jsmith.merge!({ content_type: :text })
|
||||||
assert_response :created
|
assert_response :created
|
||||||
end
|
end
|
||||||
assert_equal '1.1', @file1.last_revision.version
|
assert_equal '1.2', @file1.last_revision.version
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -163,12 +163,18 @@ class DmsfMacrosTest < RedmineDmsf::Test::HelperTest
|
|||||||
assert_not_equal "<p><p>#{@file1.description}</p></p>", text
|
assert_not_equal "<p><p>#{@file1.description}</p></p>", text
|
||||||
end
|
end
|
||||||
|
|
||||||
# {{dmsfversion(document_id)}}
|
# {{dmsfversion(document_id [, revision_id])}}
|
||||||
def test_macro_dmsfdversion
|
def test_macro_dmsfdversion
|
||||||
text = textilizable("{{dmsfversion(#{@file1.id})}}")
|
text = textilizable("{{dmsfversion(#{@file1.id})}}")
|
||||||
assert_equal "<p><p>#{@file1.version}</p></p>", text
|
assert_equal "<p><p>#{@file1.version}</p></p>", text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_macro_dmsfdversion
|
||||||
|
revision5 = DmsfFileRevision.find_by(id: 5)
|
||||||
|
text = textilizable("{{dmsfversion(#{@file1.id}, #{revision5.id})}}")
|
||||||
|
assert_equal "<p><p>#{revision5.version}</p></p>", text
|
||||||
|
end
|
||||||
|
|
||||||
def test_macro_dmsfdversion_no_permissions
|
def test_macro_dmsfdversion_no_permissions
|
||||||
@manager_role.remove_permission! :view_dmsf_files
|
@manager_role.remove_permission! :view_dmsf_files
|
||||||
text = textilizable("{{dmsfversion(#{@file1.id})}}")
|
text = textilizable("{{dmsfversion(#{@file1.id})}}")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user