eac_redmine_usability 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/config/initializers/000_dependencies.rb +6 -0
- data/config/initializers/001_patches.rb +7 -0
- data/init.rb +11 -0
- data/lib/eac_redmine_usability/close_unused_projects.rb +47 -0
- data/lib/eac_redmine_usability/close_unused_projects/project_check.rb +68 -0
- data/lib/eac_redmine_usability/patches/test_case.rb +26 -0
- data/lib/eac_redmine_usability/undeletable.rb +36 -0
- data/lib/eac_redmine_usability/version.rb +9 -0
- data/lib/tasks/eac_redmine_usability.rake +21 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb2d1808780a9a3708ce9aa03a76d0a20821fff72ed99b476554e9f3aa613455
|
4
|
+
data.tar.gz: 0bf93e1b2295af3483c0125e5312dc9f38df4b16fdd05e1974bb673438cd5db1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae529cf88b2a2124e4ca121f6b68a931dffa81ffd0407ec94cd708eea05656955d88f783583acb7a0543cbf5cea5043f050bdff753e340e856364d5c455ba935
|
7
|
+
data.tar.gz: ecd6112da3b5228082698aa58b1e4ef147d495cfafd47ab73ba6b8e9e072b448c93d4a228cc4ae08d5b52d996ec86c6b353caf64c09aaa3b76bad9f0aad469f7
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source = ::EacRedmineUsability::Undeletable
|
4
|
+
[::Issue, ::Project, ::User, ::Wiki, ::WikiPage].each do |target|
|
5
|
+
target.send(:include, source) unless target.included_modules.include? source
|
6
|
+
end
|
7
|
+
require 'eac_redmine_usability/patches/test_case'
|
data/init.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'redmine'
|
4
|
+
require 'eac_redmine_usability/version'
|
5
|
+
|
6
|
+
Redmine::Plugin.register ::EacRedmineUsability::SLUG.to_sym do
|
7
|
+
name ::EacRedmineUsability::NAME
|
8
|
+
author ::EacRedmineUsability::AUTHOR
|
9
|
+
description ::EacRedmineUsability::SUMMARY
|
10
|
+
version ::EacRedmineUsability::VERSION
|
11
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRedmineUsability
|
6
|
+
class CloseUnusedProjects
|
7
|
+
DEFAULT_EXPIRE_DAYS = 180
|
8
|
+
|
9
|
+
require_sub __FILE__
|
10
|
+
enable_simple_cache
|
11
|
+
common_constructor :expire_days, :confirm do
|
12
|
+
self.expire_days = DEFAULT_EXPIRE_DAYS unless expire_days.is_a?(::Integer) &&
|
13
|
+
expire_days.positive?
|
14
|
+
self.confirm = confirm ? true : false
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
start_bunner
|
19
|
+
expired_projects.each(&:run)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def active_projects_uncached
|
25
|
+
::Project.active.map { |project| ProjectCheck.new(self, project) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def expired_projects_uncached
|
29
|
+
active_projects.select(&:expired?).sort_by { |p| [p.expired_time] }
|
30
|
+
end
|
31
|
+
|
32
|
+
def now_uncached
|
33
|
+
::Time.zone.now
|
34
|
+
end
|
35
|
+
|
36
|
+
def start_bunner
|
37
|
+
::Rails.logger.info("Expire days: #{expire_days}")
|
38
|
+
::Rails.logger.info("Confirm: #{confirm}")
|
39
|
+
::Rails.logger.info("Active projects: #{active_projects.count}")
|
40
|
+
::Rails.logger.info("Expired projects: #{expired_projects.count}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_fetch_activity_user_uncached
|
44
|
+
::User.admin.first || raise('None admin user found')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRedmineUsability
|
6
|
+
class CloseUnusedProjects
|
7
|
+
class ProjectCheck
|
8
|
+
enable_simple_cache
|
9
|
+
common_constructor :parent, :project
|
10
|
+
|
11
|
+
def run
|
12
|
+
start_banner
|
13
|
+
close
|
14
|
+
end
|
15
|
+
|
16
|
+
def expired?
|
17
|
+
expired_days > parent.expire_days
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def start_banner
|
23
|
+
::Rails.logger.info("Project: #{project}")
|
24
|
+
::Rails.logger.info(" * Last update: #{last_update}")
|
25
|
+
::Rails.logger.info(" * Expired days: #{expired_days}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
return unless parent.confirm
|
30
|
+
|
31
|
+
if project.active?
|
32
|
+
::Rails.logger.info(' * Closing...')
|
33
|
+
project.close
|
34
|
+
else
|
35
|
+
::Rails.logger.info(' * Project is not active')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def expired_time_uncached
|
40
|
+
parent.now - last_update
|
41
|
+
end
|
42
|
+
|
43
|
+
def expired_days
|
44
|
+
(expired_time / (24 * 60 * 60)).to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
def last_update_uncached
|
48
|
+
([self_last_update] + subprojects.map(&:last_update)).max
|
49
|
+
end
|
50
|
+
|
51
|
+
def self_last_update
|
52
|
+
updates = [project.updated_on]
|
53
|
+
self_last_update_by_events.if_present { |v| updates << v }
|
54
|
+
updates.max
|
55
|
+
end
|
56
|
+
|
57
|
+
def self_last_update_by_events
|
58
|
+
::Redmine::Activity::Fetcher.new(
|
59
|
+
parent.to_fetch_activity_user, project: project, with_subprojects: false
|
60
|
+
).events.first.try(:created_on)
|
61
|
+
end
|
62
|
+
|
63
|
+
def subprojects_uncached
|
64
|
+
project.children.active.map { |child| self.class.new(parent, child) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRedmineUsability
|
4
|
+
module Patches
|
5
|
+
module TestCase
|
6
|
+
extend ::ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
setup do
|
10
|
+
::EacRedmineUsability::Undeletable.allow_destroy = true
|
11
|
+
end
|
12
|
+
|
13
|
+
teardown do
|
14
|
+
::EacRedmineUsability::Undeletable.allow_destroy = false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if ::Rails.env.test?
|
22
|
+
require Rails.root.join('test', 'test_helper.rb')
|
23
|
+
patch = ::EacRedmineUsability::Patches::TestCase
|
24
|
+
target = ::ActiveSupport::TestCase
|
25
|
+
target.send(:include, patch) unless target.included_modules.include?(patch)
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacRedmineUsability
|
4
|
+
module Undeletable
|
5
|
+
extend ::ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_destroy :block_destroy, prepend: true
|
9
|
+
include InstanceMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :allow_destroy
|
14
|
+
|
15
|
+
def on_allow_destroy(allow)
|
16
|
+
old_value = allow_destroy
|
17
|
+
begin
|
18
|
+
self.allow_destroy = allow
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
self.allow_destroy = old_value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module InstanceMethods
|
27
|
+
def block_destroy
|
28
|
+
return true if ::EacRedmineUsability::Undeletable.allow_destroy
|
29
|
+
|
30
|
+
errors.add :base, 'Este registro não pode ser removido. Em vez disso tente associá-lo a ' \
|
31
|
+
'um status como "Rejeitado" ou "Depreciado".'
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :eac_redmine_usability do
|
4
|
+
Rake::TestTask.new(test: 'db:test:prepare') do |t|
|
5
|
+
plugin_root = ::File.dirname(::File.dirname(__dir__))
|
6
|
+
|
7
|
+
t.description = 'Run plugin eac_redmine_usability\'s tests.'
|
8
|
+
t.libs << 'test'
|
9
|
+
t.test_files = FileList["#{plugin_root}/test/**/*_test.rb"]
|
10
|
+
t.verbose = false
|
11
|
+
t.warning = false
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Close projects no longer used.'
|
15
|
+
task :close_unused_projects, %i[expire_days confirm] => :environment do |_t, args|
|
16
|
+
::EacRedmineUsability::CloseUnusedProjects.new(
|
17
|
+
args.expire_days.to_i,
|
18
|
+
args.confirm.present?
|
19
|
+
).run
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eac_redmine_usability
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eduardo Henrique Bogoni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eac_ruby_utils
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.33'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.33.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.33'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.33.1
|
33
|
+
description:
|
34
|
+
email:
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- config/initializers/000_dependencies.rb
|
40
|
+
- config/initializers/001_patches.rb
|
41
|
+
- init.rb
|
42
|
+
- lib/eac_redmine_usability/close_unused_projects.rb
|
43
|
+
- lib/eac_redmine_usability/close_unused_projects/project_check.rb
|
44
|
+
- lib/eac_redmine_usability/patches/test_case.rb
|
45
|
+
- lib/eac_redmine_usability/undeletable.rb
|
46
|
+
- lib/eac_redmine_usability/version.rb
|
47
|
+
- lib/tasks/eac_redmine_usability.rake
|
48
|
+
homepage:
|
49
|
+
licenses: []
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.7.7
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: ''
|
71
|
+
test_files: []
|