Skip to content

Commit

Permalink
Merge branch 'release-v1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele Tessaro committed May 14, 2022
2 parents 459181d + 7eaa4db commit 50f334a
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 5 deletions.
34 changes: 33 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
# Changelog


## development (unreleased)
## v1.3.1 (2022-05-14)

### Fix

* Fixed mxgraph viewer patch (refs #105) [Michele Tessaro]

Fixed the patch of the viewer of diagrams in XML format, caused by a
recent change in the Drawio scripts.

### Other

* Fixed check for api enabled. [Liane Hampe]

ViewLayoutsBaseHtmlHeadHook#hash_code uses a wrong api enabled check which
would not return true if rest api is enabled.

* Fixed generating api key even if api not enabeld. [Liane Hampe]

When the api is not enabled there should be no api key requested
for the current user. Moreover, Redmine
MyControllerTest#test_reset_api_key_without_existing_key
would fail since it does not expect the current user to have an api key by
default.

Added a warning for the admin if api is disabled since the plugin needs
the api for saving diagrams as attachment.


## v1.3.0 (2022-02-19)

### Changes

* Updated CHANGELOG.md for the new release. [Michele Tessaro]

* Def: updated version for the new release. [Michele Tessaro]

* Updates.gitignore. [Liane Hampe]

Adds .history what is a vs code extension storing the history of all
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<% flash[:warning] = l(:drawio_warning_api_needs_to_be_enabled) %>
2 changes: 1 addition & 1 deletion assets/javascripts/drawioEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ window.onDrawioViewerLoad = function() {

// Patch the code `mxEvent.addListener(g,"click",b)`
var code = GraphViewer.prototype.addToolbar.toString();
var searchRegex = /mxEvent\.addListener\(([a-zA-Z]),"click",([a-zA-Z])\)/;
var searchRegex = /mxEvent\.addListener\(([a-zA-Z]+),"click",([a-zA-Z]+)\)/;
var replaceRules = "mxEvent.addListener($1,\"click\",(typeof($2)==='string'?eval($2):$2))";

code = code.replace(searchRegex, replaceRules);
Expand Down
1 change: 1 addition & 0 deletions config/locales/da.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ da:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
1 change: 1 addition & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ de:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: Um drawio Diagramme speichern zu können, muss die REST API unter Administration -> Konfiguration -> API aktiviert werden.
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ en:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
2 changes: 1 addition & 1 deletion config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ it:
drawio_dlg_page: "Pagina iniziale"
drawio_dlg_hiligh: "Colore degli hyperlink"
drawio_dlg_zoom: "Controlli zoom"

drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ ja:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
1 change: 1 addition & 0 deletions config/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ ko:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ ru:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
1 change: 1 addition & 0 deletions config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ zh-TW:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
1 change: 1 addition & 0 deletions config/locales/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ zh:
drawio_dlg_page: "Initial page"
drawio_dlg_hiligh: "Hyperlinks color"
drawio_dlg_zoom: "Zoom controls"
drawio_warning_api_needs_to_be_enabled: For saving drawio diagrams you need to enable the REST API in Administration -> Configuration -> API.
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name 'Redmine Drawio plugin'
author 'Michele Tessaro'
description 'Wiki macro plugin for inserting drawio diagrams into Wiki pages and Issues'
version '1.3.0'
version '1.3.1'
url 'https://github.com/mikitex70/redmine_drawio'
author_url 'https://github.com/mikitex70'

Expand Down
15 changes: 14 additions & 1 deletion lib/redmine_drawio/hooks/view_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

module RedmineDrawio

class ViewLayoutsBaseBodyTop < Redmine::Hook::ViewListener
def view_layouts_base_body_top(context = {})
return unless User.current.admin? && !Setting.rest_api_enabled?

context[:controller].send(:render_to_string, { partial: 'redmine_drawio/hooks/api_not_enabled_warning' })
end
end

class ViewLayoutsBaseHtmlHeadHook < Redmine::Hook::ViewListener

# This method will add the necessary CSS and JS scripts to the page header.
Expand Down Expand Up @@ -63,7 +71,7 @@ def view_layouts_base_html_head(context={})
var Drawio = {
settings: {
redmineUrl: '#{redmine_url}',
hashCode : '#{Base64.encode64(User.current.api_key).gsub(/\n/, '').reverse!}',
hashCode : '#{hash_code}',
drawioUrl : '#{drawio_url}',
DMSF : #{dmsf_enabled? context},
isEasyRedmine: #{easyredmine?}
Expand Down Expand Up @@ -132,6 +140,11 @@ def mathjax_url
url
end

def hash_code
return '' unless Setting.rest_api_enabled?

Base64.encode64(User.current.api_key).gsub(/\n/, '').reverse!
end
end

end
59 changes: 59 additions & 0 deletions test/integration/view_hooks_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# frozen_string_literal: true

# Copyright (C) 2022 Liane Hampe <[email protected]>, xmera.

require File.expand_path('test_helper', File.dirname(__dir__))
require File.expand_path('authenticate_user', File.dirname(__dir__))
require File.expand_path('load_fixtures', File.dirname(__dir__))
require File.expand_path('with_drawio_settings', File.dirname(__dir__))

class ViewHooksTest < ActionDispatch::IntegrationTest
include Redmine::I18n
include RedmineDrawio::AuthenticateUser
include RedmineDrawio::LoadFixtures
include RedmineDrawio::WithDrawioSettings

fixtures :users, :email_addresses, :roles

def setup
@hook = RedmineDrawio::ViewLayoutsBaseHtmlHeadHook.instance
end

def teardown
Setting.rest_api_enabled = nil
end

test 'render warning_api_needs_to_be_enabled when api is disabled' do
render_view_hooks(user: 'admin', password: 'admin')
assert_select '#flash_warning', text: l(:drawio_warning_api_needs_to_be_enabled)
end

test 'do not render warning_api_needs_to_be_enabled when api is enabled' do
render_view_hooks(user: 'admin', password: 'admin', rest_api_enabled: '1')
assert_select '#flash_warning', 0
end

test 'do not render warning_api_needs_to_be_enabled for non admin user' do
render_view_hooks(user: 'jsmith', password: 'jsmith', rest_api_enabled: '1')
assert_select '#flash_warning', 0
end

test 'do not render hash code when api is disabled' do
render_view_hooks(user: 'admin', password: 'admin')
assert @hook.send(:hash_code).blank?
end

test 'render hash code when api is enabled' do
render_view_hooks(user: 'admin', password: 'admin', rest_api_enabled: '1')
assert @hook.send(:hash_code).present?
end

private

def render_view_hooks(user:, password:, rest_api_enabled: '0')
Setting.rest_api_enabled = rest_api_enabled
log_user(user, password)
get '/'
assert_response :success
end
end

0 comments on commit 50f334a

Please sign in to comment.