web47core 3.2.5 → 3.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97511542e4fd2facae8f07554574360af309703a4c4e60236087f0ce8c9d1647
4
- data.tar.gz: 1fe0abc1e0e93fb4a33672f53ee244777616c4f8e4c146204d4c5d273cab8490
3
+ metadata.gz: '09bd1177ff541dc974ea27c1208e06c43be1056962384b6250e52bfc2938fd6b'
4
+ data.tar.gz: 119fcf27352d87d96ef84328e24cc7adbf6cbe1e18363a2535826e5bb5c3a90d
5
5
  SHA512:
6
- metadata.gz: fee9f5c0965942cb3e292b71ca556156bbacfe5e87a0c59aeb4b289a2301523ae112401fbe15619928c3551f89ad8a8f21ada2fb5584d8c51a94b14e4b0221bf
7
- data.tar.gz: 76ce06f3fb886cee25351187b02fb6fbf83c45f40ce902257b0786b79c82879f48b74311a7ab6f7bf569dbb51b53cf1fd3aa780471e73c9be5bba2fac675fc15
6
+ metadata.gz: 38926fb70d61e60d8633fcd89e58d2a5e66dca47ac9245eeb31c3de8264917e547d13740819df61850805a06631b69b22929643310feb0a9458fbd893881d9cf
7
+ data.tar.gz: 061e7c166c012d860b4c66521c2d178943197a1384c0f195ea331d13087b0a0801def262f28b85083c149388368d273cf04adf303632dcc8913b98c798ff036c
@@ -37,16 +37,22 @@ class CommandJob
37
37
  #
38
38
  validates :state, inclusion: { in: ALL_STATES }
39
39
 
40
- #
41
- # Who started this job
42
- #
40
+ # @abstract duration for the job
41
+ # @return Integer - How long this job took in milliseconds
42
+ def duration
43
+ finished_at - started_at
44
+ rescue StandardError
45
+ 0
46
+ end
47
+
48
+ # @abstract Who started this job
49
+ # @return String - Who started this job if present, otherwise `System`
43
50
  def display_started_by
44
51
  started_by.present? ? started_by.name : 'System'
45
52
  end
46
53
 
47
- #
48
- # Default time to keep a job before auto archiving it
49
- #
54
+ # @abstract Default time to keep a job before auto archiving it
55
+ # @return Integer - TTL for this job
50
56
  def ttl
51
57
  30
52
58
  end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # A module that allows for trash/recycling of an object
5
+ # it will be deleted in the app, but remain in the database until permanently deleted
6
+ #
7
+ module ArchiveAble
8
+ extend ActiveSupport::Concern
9
+
10
+ def self.included(base)
11
+ base.class_eval do
12
+ # Fields
13
+ field :archived, type: Mongoid::Boolean, default: false
14
+ field :archived_at, type: Time
15
+ field :archived_by_name, type: String
16
+ field :archived_by_email, type: String
17
+ field :restored_at, type: Time
18
+ field :restored_by_name, type: String
19
+ field :restored_by_email, type: String
20
+ # Relationships
21
+ belongs_to :archived_by, polymorphic: true, optional: true, inverse_of: nil
22
+ belongs_to :restored_by, polymorphic: true, optional: true, inverse_of: nil
23
+ end
24
+ end
25
+
26
+ # @abstract Display who archived this object
27
+ # @return String
28
+ def display_archived_by
29
+ if archived_by.present?
30
+ archived_by.display_name
31
+ elsif archived_by_email.present?
32
+ "#{archived_by_name} (#{archived_by_email})"
33
+ else
34
+ archived_by_name
35
+ end
36
+ end
37
+
38
+ # @abstract Display who restored this object
39
+ # @return String
40
+ def display_restored_by
41
+ if restored_by.present?
42
+ restored_by.display_name
43
+ elsif restored_by_email.present?
44
+ "#{restored_by_name} (#{restored_by_email})"
45
+ else
46
+ restored_by_name
47
+ end
48
+ end
49
+
50
+ def unarchived?
51
+ !archived?
52
+ end
53
+
54
+ # @abstract Archive the object
55
+ # @param [Member|User] actor - the thing performing the action
56
+ def archive(actor)
57
+ params = if actor.is_a? Cron::Job
58
+ { archived: true,
59
+ archived_at: Time.now.utc,
60
+ archived_by_name: "System - #{actor.class.name}" }
61
+ else
62
+ { archived: true,
63
+ archived_by: actor,
64
+ archived_at: Time.now.utc,
65
+ archived_by_name: actor.name,
66
+ archived_by_email: actor.email }
67
+ end
68
+ params[:name] = "#{name}-(archived at #{Time.now.utc})" if respond_to?(:name=)
69
+ update params
70
+ end
71
+
72
+ # @abstract recycle the object
73
+ # @param [Member|User] actor - the actor performing the action
74
+ def restore(actor)
75
+ params = { archived: false,
76
+ restored_by: actor,
77
+ restored_at: Time.now.utc,
78
+ restored_by_name: actor.name,
79
+ restored_by_email: actor.email }
80
+ params[:name] = name.split('-(archived at').first if respond_to?(:name=)
81
+ update params
82
+ end
83
+
84
+ def days_to_deletion
85
+ archived? ? ((archived_at + retention_days.days - Time.now.utc) / 86_400).to_i : 0
86
+ rescue StandardError
87
+ archived? ? retention_days : 0
88
+ end
89
+
90
+ def retention_days
91
+ 30
92
+ end
93
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Web47core
4
- VERSION = '3.2.5'
4
+ VERSION = '3.2.6'
5
5
  end
data/lib/web47core.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'web47core/config'
2
2
  require 'app/models/concerns/app47_logger'
3
3
  require 'app/models/concerns/api_tokenable'
4
+ require 'app/models/concerns/archive_able'
4
5
  require 'app/models/concerns/aws_configuration'
5
6
  require 'app/models/concerns/core_system_configuration'
6
7
  require 'app/models/concerns/core_account'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.5
4
+ version: 3.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-21 00:00:00.000000000 Z
11
+ date: 2024-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -645,6 +645,7 @@ files:
645
645
  - lib/app/models/command_job_log.rb
646
646
  - lib/app/models/concerns/api_tokenable.rb
647
647
  - lib/app/models/concerns/app47_logger.rb
648
+ - lib/app/models/concerns/archive_able.rb
648
649
  - lib/app/models/concerns/aws_configuration.rb
649
650
  - lib/app/models/concerns/cdn_url.rb
650
651
  - lib/app/models/concerns/cipher_able.rb
@@ -712,7 +713,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
712
713
  - !ruby/object:Gem::Version
713
714
  version: '0'
714
715
  requirements: []
715
- rubygems_version: 3.1.2
716
+ rubygems_version: 3.5.13
716
717
  signing_key:
717
718
  specification_version: 4
718
719
  summary: App47 Web Core Library.