Redmine 3.4

This commit is contained in:
Karel Picman 2017-07-21 13:43:51 +02:00
parent 3f78b964c0
commit abbaea2692
25 changed files with 76 additions and 72 deletions

View File

@ -24,12 +24,12 @@
class DmsfController < ApplicationController
unloadable
before_filter :find_project
before_filter :authorize, :except => [:expand_folder]
before_filter :find_folder, :except => [:new, :create, :edit_root, :save_root]
before_filter :find_parent, :only => [:new, :create]
before_filter :tree_view, :only => [:delete, :show]
before_filter :permissions
before_action :find_project
before_action :authorize, :except => [:expand_folder]
before_action :find_folder, :except => [:new, :create, :edit_root, :save_root]
before_action :find_parent, :only => [:new, :create]
before_action :tree_view, :only => [:delete, :show]
before_action :permissions
accept_api_auth :show, :create, :save

View File

@ -24,11 +24,11 @@ class DmsfFilesController < ApplicationController
menu_item :dmsf
before_filter :find_file, :except => [:delete_revision]
before_filter :find_revision, :only => [:delete_revision]
before_filter :authorize
before_filter :tree_view, :only => [:delete]
before_filter :permissions
before_action :find_file, :except => [:delete_revision]
before_action :find_revision, :only => [:delete_revision]
before_action :authorize
before_action :tree_view, :only => [:delete]
before_action :permissions
accept_api_auth :show
@ -312,7 +312,7 @@ class DmsfFilesController < ApplicationController
:disposition => 'inline'
end
else
render :nothing => true, :status => 404
head 404
end
end

View File

@ -22,9 +22,9 @@ class DmsfFilesCopyController < ApplicationController
menu_item :dmsf
before_filter :find_file
before_filter :authorize
before_filter :permissions
before_action :find_file
before_action :authorize
before_action :permissions
helper :all

View File

@ -21,10 +21,10 @@
class DmsfFolderPermissionsController < ApplicationController
unloadable
before_filter :find_folder, :only => [:destroy]
before_filter :find_project
before_filter :authorize
before_filter :permissions
before_action :find_folder, :only => [:destroy]
before_action :find_project
before_action :authorize
before_action :permissions
def permissions
render_403 unless DmsfFolder.permissions?(@dmsf_folder)

View File

@ -21,9 +21,9 @@ class DmsfFoldersCopyController < ApplicationController
menu_item :dmsf
before_filter :find_folder
before_filter :authorize
before_filter :permissions
before_action :find_folder
before_action :authorize
before_action :permissions
def permissions
render_403 unless DmsfFolder.permissions?(@folder)

View File

@ -22,10 +22,10 @@ class DmsfLinksController < ApplicationController
unloadable
model_object DmsfLink
before_filter :find_model_object, :only => [:destroy, :restore]
before_filter :find_link_project
before_filter :authorize
before_filter :permissions
before_action :find_model_object, :only => [:destroy, :restore]
before_action :find_link_project
before_action :authorize
before_action :permissions
protect_from_forgery except: :new
def permissions

View File

@ -22,8 +22,8 @@ class DmsfPublicUrlsController < ApplicationController
unloadable
model_object DmsfPublicUrl
before_filter :authorize, :only => [:create]
skip_before_filter :check_if_login_required, :only => [:show]
before_action :authorize, :only => [:create]
skip_before_action :check_if_login_required, :only => [:show]
def show
dmsf_public_url = DmsfPublicUrl.where('token = ? AND expire_at >= ?', params[:token], DateTime.now).first

View File

@ -24,8 +24,8 @@ class DmsfStateController < ApplicationController
menu_item :dmsf
before_filter :find_project
before_filter :authorize
before_action :find_project
before_action :authorize
def user_pref_save
member = @project.members.where(:user_id => User.current.id).first

View File

@ -24,11 +24,11 @@ class DmsfUploadController < ApplicationController
menu_item :dmsf
before_filter :find_project, :except => [:upload, :delete_dmsf_attachment]
before_filter :authorize, :except => [:upload, :delete_dmsf_attachment]
before_filter :authorize_global, :only => [:upload, :delete_dmsf_attachment]
before_filter :find_folder, :except => [:upload_file, :upload, :commit, :delete_dmsf_attachment]
before_filter :permissions, :except => [:upload_file, :upload, :commit, :delete_dmsf_attachment]
before_action :find_project, :except => [:upload, :delete_dmsf_attachment]
before_action :authorize, :except => [:upload, :delete_dmsf_attachment]
before_action :authorize_global, :only => [:upload, :delete_dmsf_attachment]
before_action :find_folder, :except => [:upload_file, :upload, :commit, :delete_dmsf_attachment]
before_action :permissions, :except => [:upload_file, :upload, :commit, :delete_dmsf_attachment]
helper :all
helper :dmsf_workflows

View File

@ -22,10 +22,10 @@ class DmsfWorkflowsController < ApplicationController
unloadable
model_object DmsfWorkflow
before_filter :find_model_object, :except => [:create, :new, :index, :assign, :assignment]
before_filter :find_project
before_filter :authorize_custom
before_filter :permissions, :only => [:new_action, :assignment, :start]
before_action :find_model_object, :except => [:create, :new, :index, :assign, :assignment]
before_action :find_project
before_action :authorize_custom
before_action :permissions, :only => [:new_action, :assignment, :start]
layout :workflows_layout
@ -332,7 +332,7 @@ class DmsfWorkflowsController < ApplicationController
def add_step
if request.post?
if params[:step] == '0'
step = @dmsf_workflow.dmsf_workflow_steps.collect{|s| s.step}.uniq.count + 1
step = @dmsf_workflow.dmsf_workflow_steps.collect{|s| s.step}.distinct.count + 1
else
step = params[:step].to_i
end

View File

@ -43,5 +43,5 @@ class DmsfFileRevisionAccess < ActiveRecord::Base
:scope => select("#{DmsfFileRevisionAccess.table_name}.*").
joins(:dmsf_file_revision).joins("JOIN #{DmsfFile.table_name} ON dmsf_files.id = dmsf_file_revisions.dmsf_file_id").
joins("JOIN #{Project.table_name} on dmsf_files.project_id = projects.id").
where(["#{DmsfFile.table_name}.deleted = ?", DmsfFile::STATUS_ACTIVE])
where(:dmsf_files => { :deleted => DmsfFile::STATUS_ACTIVE })
end

View File

@ -22,8 +22,8 @@ class DmsfWorkflow < ActiveRecord::Base
has_many :dmsf_workflow_steps, -> { order 'step ASC, operator DESC' }, :dependent => :destroy
belongs_to :author, :class_name => 'User'
scope :sorted, lambda { order('name ASC') }
scope :global, lambda { where('project_id IS NULL') }
scope :sorted, lambda { order(:name => :asc) }
scope :global, lambda { where(:project_id => nil) }
scope :active, lambda { where(:status => STATUS_ACTIVE) }
scope :status, lambda { |arg| where(arg.blank? ? nil : {:status => arg.to_i}) }

View File

@ -1,7 +1,6 @@
<% parent = @folder ? @folder : @project %>
<% DmsfHelper.all_children_sorted(parent, @pos, @idnt).each do |obj, position| %>
<% classes = "dmsf_tree idnt-#{@idnt}" %>
<% classes += " dmsf-#{cycle('odd', 'even')}" %>
<% if obj.is_a?(DmsfFolder) && ((obj.dmsf_folders.visible.count > 0) || (obj.dmsf_files.visible.count > 0) || (obj.dmsf_links.visible.count > 0)) %>
<% classes += ' idnt dmsf_collapsed dmsf-not-loaded' %>
<% id = "id='#{obj.id}span'".html_safe %>

View File

@ -82,7 +82,7 @@
<% result = DmsfWorkflowStep.connection.exec_query sql %>
<% last_step = 0 %>
<% result.each_with_index do |row, i| %>
<tr id="step-<%= i + 3 %> " class="<%= cycle 'odd', 'even' %>">
<tr id="step-<%= i + 3 %>">
<td class="id"><%= row['step'] unless row['step'] == last_step %></td>
<% last_step = row['step'] %>
<td class="name"><%= row['name'] %></td>

View File

@ -47,7 +47,7 @@
</tr></thead>
<tbody>
<% for workflow in @workflows %>
<tr id="workflow-<%= workflow.id %>" class="dmsf_workflows <%= workflow.active? ? 'active' : 'locked' %> <%= cycle('odd', 'even') %>">
<tr id="workflow-<%= workflow.id %>" class="dmsf_workflows <%= workflow.active? ? 'active' : 'locked' %>">
<td class="name"><%= link_to(h(workflow.name), dmsf_workflow_path(workflow)) %></td>
<td class="buttons">
<%= change_status_link(workflow) unless @project %>

View File

@ -51,7 +51,7 @@
</tr></thead>
<tbody>
<% steps.each do |i|%>
<tr id="step-<%= i %>" class="<%= cycle 'odd', 'even' %> step">
<tr id="step-<%= i %>" class="step">
<% index = @dmsf_workflow.dmsf_workflow_steps.order(:id).index{ |s| s.step == i } %>
<%= form_for(@dmsf_workflow,
:url => update_step_dmsf_workflow_path(:step => index),
@ -115,7 +115,7 @@
<%= delete_link edit_dmsf_workflow_path(@dmsf_workflow, :step => i) %>
</td>
</tr>
<% end; reset_cycle %>
<% end %>
</tbody>
</table>
<% else %>

View File

@ -43,7 +43,7 @@
</thead>
<tbody>
<% folders.each do |folder| %>
<tr id="folder-<%= folder.id %>" class="<%= cycle('odd', 'even') %>">
<tr id="folder-<%= folder.id %>">
<td class="project">
<%= link_to_project(folder.project) %>
</td>
@ -63,7 +63,7 @@
</tr>
<% end %>
<% files.each do |file| %>
<tr id="file-<%= file.id %>" class="<%= cycle('odd', 'even') %>">
<tr id="file-<%= file.id %>">
<td class="project">
<%= link_to_project(file.project) %>
</td>

View File

@ -24,7 +24,7 @@
<% if @user %>
<% all_assignments = DmsfWorkflowStepAssignment.joins(
'LEFT JOIN dmsf_workflow_step_actions ON dmsf_workflow_step_assignments.id = dmsf_workflow_step_actions.dmsf_workflow_step_assignment_id').where(
'dmsf_workflow_step_assignments.user_id = ? AND dmsf_workflow_step_actions.id IS NULL', @user.id).all %>
:dmsf_workflow_step_assignments => { :user_id => @user.id }, :dmsf_workflow_step_actions => { :id => nil }) %>
<% all_assignments.each do |assignment| %>
<% if assignment.dmsf_file_revision.dmsf_file.last_revision &&
!assignment.dmsf_file_revision.dmsf_file.last_revision.deleted? &&
@ -50,7 +50,7 @@
</thead>
<tbody>
<% assignments.each do |assignment| %>
<tr id="assignment-<%= assignment.id %>" class="<%= cycle('odd', 'even') %>">
<tr id="assignment-<%= assignment.id %>">
<td class="project">
<% if assignment.dmsf_file_revision.dmsf_file.project %>
<%= link_to_project(assignment.dmsf_file_revision.dmsf_file.project) %>

View File

@ -46,9 +46,9 @@ class Dmsf144 < ActiveRecord::Migration
# data into it, which should enable us to run checks we need, not as
# efficient, however compatible across the board.
DmsfFileLock.reset_column_information
DmsfFileLock.select("MAX(#{DmsfFileLock.table_name}.id) id").
order("MAX(#{DmsfFileLock.table_name}.id) DESC").
group("#{DmsfFileLock.table_name}.dmsf_file_id").
DmsfFileLock.select('MAX(id) id').
order('MAX(id) DESC').
group('dmsf_file_id').
each do |lock|
lock.reload
if (lock.locked)
@ -66,7 +66,7 @@ class Dmsf144 < ActiveRecord::Migration
say "Preserving #{do_not_delete.count} file lock(s) found in old schema"
DmsfFileLock.delete_all(['id NOT IN (?)', do_not_delete])
DmsfFileLock.where(['id NOT IN (?)', do_not_delete]).delete_all
#We need to force our newly found
@ -123,7 +123,7 @@ class Dmsf144 < ActiveRecord::Migration
#Data cleanup - delete all expired locks, or any folder locks
DmsfFileLock.reset_column_information
say 'Removing all expired and/or folder locks'
DmsfFileLock.delete_all ['expires_at < ? OR entity_type = 1', Time.now]
DmsfFileLock.where(['expires_at < ? OR entity_type = 1', Time.now]).delete_all
say 'Changing all records to be locked'
DmsfFileLock.update_all ['locked = ?', true]

View File

@ -64,7 +64,7 @@ class DmsfFileContainerRollback < ActiveRecord::Migration
def down
# dmsf_files
file_folder_ids = DmsfFile.joins(:dmsf_folder).where('dmsf_folders.system = 1').pluck('dmsf_files.id, cast(dmsf_folders.title as unsigned)')
file_folder_ids = DmsfFile.joins(:dmsf_folder).where(:dmsf_folders => { :system => true }).pluck('dmsf_files.id, cast(dmsf_folders.title as unsigned)')
remove_index :dmsf_files, :project_id
rename_column :dmsf_files, :project_id, :container_id
add_column :dmsf_files, :container_type, :string, :limit => 30, :null => false, :default => 'Project'

View File

@ -33,7 +33,7 @@ module RedmineDmsf
@projects = []
Project.select(:id, :identifier, :name).has_module(:dmsf).where(
Project.allowed_to_condition(
User.current, :view_dmsf_folders)).order('lft').all.each do |p|
User.current, :view_dmsf_folders)).order('lft').each do |p|
@projects << child_project(p)
end
end

View File

@ -68,7 +68,7 @@ class DmsfConvertDocuments
folder = DmsfFolder.new
folder.project = project
attachment = document.attachments.reorder("#{Attachment.table_name}.created_on ASC").first
attachment = document.attachments.reorder(:created_on => :asc).first
if attachment
folder.user = attachment.author
else

View File

@ -200,7 +200,7 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
:user_ids => [@user_non_member.id]
end
assert_response :success
ws = DmsfWorkflowStep.order('id DESC').first
ws = DmsfWorkflowStep.order(:id => :desc).first
assert_equal @wf1.id, ws.dmsf_workflow_id
assert_equal 1, ws.step
assert_equal '1st step', ws.name
@ -214,7 +214,7 @@ class DmsfWorkflowsControllerTest < RedmineDmsf::Test::TestCase
delete :remove_step, :step => @wfs1.id, :id => @wf1.id
end
assert_response :redirect
ws = DmsfWorkflowStep.where(:dmsf_workflow_id => @wf1.id).order('id ASC').first
ws = DmsfWorkflowStep.where(:dmsf_workflow_id => @wf1.id).order(:id =>:asc).first
assert_equal 1, ws.step
end

View File

@ -22,11 +22,11 @@ require File.expand_path('../../../test_helper', __FILE__)
class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
fixtures :projects, :users, :dmsf_files, :dmsf_file_revisions, :members, :roles
fixtures :projects, :users, :dmsf_files, :dmsf_file_revisions, :members, :roles, :member_roles
def setup
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
timestamp = DateTime.now.strftime("%y%m%d%H%M")
timestamp = DateTime.now.strftime('%y%m%d%H%M')
@tmp_storage_path = File.expand_path("./dmsf_test-#{timestamp}", DmsfHelper.temp_dir)
Dir.mkdir(@tmp_storage_path) unless File.directory?(@tmp_storage_path)
@jsmith = User.find_by_id 2
@ -34,6 +34,7 @@ class DmsfFileApiTest < RedmineDmsf::Test::IntegrationTest
Setting.rest_api_enabled = '1'
@role = Role.find_by_id 1
@project1 = Project.find_by_id 1
@project1.enable_module! :dmsf
end
def teardown

View File

@ -22,7 +22,8 @@ require File.expand_path('../../../test_helper', __FILE__)
class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :projects, :users, :members, :roles
fixtures :dmsf_folders, :dmsf_files, :dmsf_file_revisions, :projects, :users, :members, :roles,
:member_roles
def setup
Setting.plugin_redmine_dmsf['dmsf_storage_directory'] = File.expand_path '../../../fixtures/files', __FILE__
@ -31,6 +32,8 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
@folder1 = DmsfFolder.find_by_id 1
Setting.rest_api_enabled = '1'
@role = Role.find_by_id 1
@project1 = Project.find_by_id 1
@project1.enable_module! :dmsf
end
def test_truth
@ -38,13 +41,14 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
assert_kind_of DmsfFolder, @folder1
assert_kind_of DmsfFile, @file1
assert_kind_of Role, @role
assert_kind_of Project, @project1
end
def test_list_folder
@role.add_permission! :view_dmsf_folders
token = Token.create!(:user => @jsmith, :action => 'api')
#curl -v -H "Content-Type: application/xml" -X GET -u ${1}:${2} http://localhost:3000/dmsf/files/17216.xml
get "/projects/1/dmsf.xml?key=#{token.value}"
get "/projects/#{@project1.id}/dmsf.xml?key=#{token.value}"
assert_response :success
assert_equal 'application/xml', @response.content_type
# <?xml version="1.0" encoding="UTF-8"?>
@ -87,7 +91,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
<dmsf_folder_id/>
</dmsf_folder>
}
post "/projects/1/dmsf/create.xml?&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'}
post "/projects/#{@project1.id}/dmsf/create.xml?&key=#{token.value}", payload, {'CONTENT_TYPE' => 'application/xml'}
assert_response :success
# <?xml version="1.0" encoding="UTF-8"?>
# <dmsf_folder>
@ -101,7 +105,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
@role.add_permission! :view_dmsf_folders
token = Token.create!(:user => @jsmith, :action => 'api')
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
get "/projects/1/dmsf.xml?key=#{token.value}&folder_title=#{@folder1.title}"
get "/projects/#{@project1.id}/dmsf.xml?key=#{token.value}&folder_title=#{@folder1.title}"
assert_response :success
assert_equal 'application/xml', @response.content_type
# <?xml version="1.0" encoding="UTF-8"?>
@ -129,7 +133,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
@role.add_permission! :view_dmsf_folders
token = Token.create!(:user => @jsmith, :action => 'api')
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KEY" http://localhost:3000/projects/1/dmsf.json?folder_title=Updated%20title
get "/projects/1/dmsf.xml?key=#{token.value}&folder_title=xxx"
get "/projects/#{@project1.id}/dmsf.xml?key=#{token.value}&folder_title=xxx"
assert_response :missing
end
@ -137,7 +141,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
@role.add_permission! :view_dmsf_folders
token = Token.create!(:user => @jsmith, :action => 'api')
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3
get "/projects/1/dmsf.xml?key=#{token.value}&folder_id=#{@folder1.id}"
get "/projects/#{@project1.id}/dmsf.xml?key=#{token.value}&folder_id=#{@folder1.id}"
assert_response :success
assert_equal 'application/xml', @response.content_type
# <?xml version="1.0" encoding="UTF-8"?>
@ -165,7 +169,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
@role.add_permission! :view_dmsf_folders
token = Token.create!(:user => @jsmith, :action => 'api')
# curl -v -H "Content-Type: application/json" -X GET -H "X-Redmine-API-Key: USERS_API_KE" http://localhost:3000/projects/1/dmsf.json?folder_id=3
get "/projects/1/dmsf.xml?key=#{token.value}&folder_id=99999999999"
get "/projects/#{@project1.id}/dmsf.xml?key=#{token.value}&folder_id=99999999999"
assert_response :missing
end
@ -180,7 +184,7 @@ class DmsfFolderApiTest < RedmineDmsf::Test::IntegrationTest
<description>A folder updated via REST API</description>
</dmsf_folder>
}
post "/projects/1/dmsf/save.xml?folder_id=1&key=#{token.value}", payload, {"CONTENT_TYPE" => 'application/xml'}
post "/projects/#{@project1.id}/dmsf/save.xml?folder_id=1&key=#{token.value}", payload, {'CONTENT_TYPE' => 'application/xml'}
assert_response :success
# <?xml version="1.0" encoding="UTF-8"?>
# <dmsf_folder>