ecm_audited_backend 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +16 -0
  5. data/app/assets/javascripts/ecm/audited/backend/application/dummy.js +0 -0
  6. data/app/assets/javascripts/ecm/audited/backend/application.js +13 -0
  7. data/app/assets/javascripts/ecm_audited_backend.js +1 -0
  8. data/app/assets/stylesheets/ecm/audited/backend/application/dummy.css +0 -0
  9. data/app/assets/stylesheets/ecm/audited/backend/application.css +3 -0
  10. data/app/assets/stylesheets/ecm_audited_backend.css +3 -0
  11. data/app/controllers/concerns/controller/ecm/audited/audit_log_concern.rb +26 -0
  12. data/app/controllers/ecm/audited/backend/application_controller.rb +8 -0
  13. data/app/controllers/ecm/audited/backend/audit_logs_controller.rb +13 -0
  14. data/app/controllers/ecm/audited/backend/home_controller.rb +4 -0
  15. data/app/helpers/ecm/audited/backend/application_helper.rb +8 -0
  16. data/app/views/ecm/audited/backend/audits/_index_extras.haml +4 -0
  17. data/app/views/itsf/backend/resource/base/audit_log.haml +21 -0
  18. data/app/views/layouts/ecm/audited/backend/application.html.erb +14 -0
  19. data/config/initializers/assets.rb +2 -0
  20. data/config/initializers/itsf_backend.rb +42 -0
  21. data/config/locales/de.yml +12 -0
  22. data/config/locales/en.yml +7 -0
  23. data/config/routes.rb +5 -0
  24. data/lib/ecm/audited/backend/configuration.rb +14 -0
  25. data/lib/ecm/audited/backend/engine.rb +19 -0
  26. data/lib/ecm/audited/backend/version.rb +7 -0
  27. data/lib/ecm/audited/backend.rb +9 -0
  28. data/lib/ecm_audited_backend.rb +2 -0
  29. data/lib/tasks/ecm/audited/backend_tasks.rake +4 -0
  30. metadata +86 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e20707044a6d73568093ce74f0bde459665a155f
4
+ data.tar.gz: 552b52987885353cb277d40560d82975669cc4ee
5
+ SHA512:
6
+ metadata.gz: a4456c8338ec898452349f5b5e56ade74adf513f56b96f83ac810e3e5e7b10e3bfeadd7a40580f4027d72f8132bad844396dab31fc86150904dbf550ffc0cadc
7
+ data.tar.gz: 2371355d0ca7e86caf6bbb0bc184f40e26f248648a12d944e4da2d9542c38bb95ad1669481cbe095b0b8c2db1fd8bc4f0c0b13d2d32aa55abe20e498150d43c2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Roberto Vasquez Angel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Ecm::Audited::Backend
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ecm::Audited::Backend'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree ./application
@@ -0,0 +1 @@
1
+ //= require ecm/audited/backend/application.js
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree ./application
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require ecm/audited/backend/application.css
3
+ */
@@ -0,0 +1,26 @@
1
+ module Controller
2
+ module Ecm::Audited
3
+ module AuditLogConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ def audit_log
7
+ @resource = load_resource
8
+ end
9
+
10
+ def revert
11
+ @resource = load_resource
12
+ @target_version = @resource.revision(params[:version])
13
+ if @target_version.save
14
+ redirect_to resource_path(@target_version), notice: t('.success')
15
+ else
16
+ redirect_to resource_path(@target_version), notice: t('.failure')
17
+ end
18
+ end
19
+
20
+ def version
21
+ @resource = load_resource.revision(params[:version])
22
+ render :show
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ module Ecm
2
+ module Audited
3
+ module Backend
4
+ class ApplicationController < ActionController::Base
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module Ecm::Audited::Backend
2
+ class AuditLogsController < Itsf::Backend::Resource::BaseController
3
+ def self.resource_class
4
+ Ecm::Audited::AuditLog
5
+ end
6
+
7
+ private
8
+
9
+ def disabled_features
10
+ [:ransack]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Ecm::Audited::Backend
2
+ class HomeController < Itsf::Backend::HomeController
3
+ end
4
+ end
@@ -0,0 +1,8 @@
1
+ module Ecm
2
+ module Audited
3
+ module Backend
4
+ module ApplicationHelper
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ %h2= t('.audited_models')
2
+ %ul
3
+ - Ecm::Audited::Configuration.audited_models.call.each do |model, options|
4
+ %li= model.model_name.human
@@ -0,0 +1,21 @@
1
+ #resource-pages-naviatio.bottom-margin-1
2
+ = render 'resource_pages_navigation', resource: @resource
3
+
4
+ %h1= t('.heading', resource: @resource.try_all(*Itsf::Backend::Configuration.resource_title_methods))
5
+
6
+ .panel.panel-default
7
+ = render_collection @resource.audits.reorder(version: :desc), Audited::Audit, as: :bootstrap_table do |table|
8
+ = table.association :auditable
9
+ = table.association :associated
10
+ = table.association :user
11
+ = table.column :user_type
12
+ = table.column :username
13
+ = table.column :action
14
+ = table.column :audited_changes
15
+ = table.column :version
16
+ = table.column :comment
17
+ = table.column :remote_address
18
+ = table.column :request_uuid
19
+ = table.column :created_at
20
+ = table.column :actions do |resource|
21
+ = button_to t('.revert'), url_for(action: 'revert', version: resource.version), class: 'btn btn-xs btn-warning'
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Backend</title>
5
+ <%= stylesheet_link_tag "ecm/audited/backend/application", media: "all" %>
6
+ <%= javascript_include_tag "ecm/audited/backend/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,2 @@
1
+ Rails.application.config.assets.precompile += %w( ecm_audited_backend.css )
2
+ Rails.application.config.assets.precompile += %w( ecm_audited_backend.js )
@@ -0,0 +1,42 @@
1
+ Itsf::Backend.configure do |config|
2
+ config.resource_links += [
3
+ {
4
+ condition: ->(view) { Ecm::Audited.audited_models.call.keys.include?(view.controller.resource_class) },
5
+ target: ->(view) { view.url_for(action: :audit_log) },
6
+ link_to: ->(view) {
7
+ view.link_to(
8
+ view.t(".audit_log", audits_count: view.instance_variable_get(:@resource)),
9
+ view.url_for(action: :audit_log)
10
+ )
11
+ }
12
+ }
13
+ ]
14
+
15
+ # This has to be refactored
16
+ config.additional_resource_route_blocks += [
17
+ ->(router) do
18
+ # Find out if the resource uses audited
19
+ __controller = router.instance_variable_get(:@scope).instance_variable_get(:@hash)[:controller]
20
+ __namespaces = []
21
+ __actual_scope = router.instance_variable_get(:@scope)
22
+ while __actual_scope.instance_variable_get(:@parent).present?
23
+ __namespaces << __actual_scope.instance_variable_get(:@parent).instance_variable_get(:@hash).try(:[], :module)
24
+ __actual_scope = __actual_scope.instance_variable_get(:@parent)
25
+ end
26
+ __namespace = __namespaces.uniq.reverse.compact.join("/")
27
+
28
+ __controller = "#{__namespace}/#{__controller}_controller".camelize.constantize
29
+ # This should be lazy
30
+ __resource_class = __controller.resource_class
31
+ __is_audited = Ecm::Audited.audited_models.call.keys.include?(__resource_class)
32
+
33
+ # Add routes
34
+ if __is_audited
35
+ Rails.logger.info "Injecting audited routes to #{__resource_class} backend routes"
36
+ router.get 'audit_log', action: :audit_log, on: :member
37
+ router.post 'revert/:version', action: :revert, on: :member
38
+ router.get 'versions/:version', action: :version, on: :member
39
+ end
40
+ end
41
+ ]
42
+ end
@@ -0,0 +1,12 @@
1
+ de:
2
+ classes:
3
+ ecm/audited/backend/engine: "Audit Logs (Beta)"
4
+ itsf:
5
+ backend:
6
+ resource:
7
+ base:
8
+ audit_log:
9
+ heading: "Audit Log für %{resource}"
10
+ revert: Wiederherstellen
11
+ resource_pages_navigation:
12
+ audit_log: Audit Log
@@ -0,0 +1,7 @@
1
+ en:
2
+ itsf:
3
+ backend:
4
+ resource:
5
+ base:
6
+ resource_pages_navigation:
7
+ audit_log: Audit Log
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Ecm::Audited::Backend::Engine.routes.draw do
2
+ resources :audit_logs, only: [:index, :show]
3
+
4
+ root to: 'home#index'
5
+ end
@@ -0,0 +1,14 @@
1
+ module Ecm
2
+ module Audited
3
+ module Backend
4
+ module Configuration
5
+ def configure
6
+ yield self
7
+ end
8
+
9
+ mattr_accessor(:registered_controllers) { -> { [] } }
10
+ mattr_accessor(:registered_services) { -> { [] } }
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module Ecm
2
+ module Audited
3
+ module Backend
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Ecm::Audited::Backend
6
+
7
+ config.paths.add root.join(*%w(app extensions concerns)).to_s, eager_load: true
8
+
9
+ config.to_prepare do
10
+ puts "Including Controller::Ecm::Audited::AuditLogConcern into Itsf::Backend::Resource::BaseController."
11
+ Itsf::Backend::Resource::BaseController.send(:include, Controller::Ecm::Audited::AuditLogConcern)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+
19
+
@@ -0,0 +1,7 @@
1
+ module Ecm
2
+ module Audited
3
+ module Backend
4
+ VERSION = '0.0.1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'ecm/audited/backend/configuration'
2
+
3
+ module Ecm
4
+ module Audited
5
+ module Backend
6
+ extend Configuration
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'ecm/audited/backend'
2
+ require 'ecm/audited/backend/engine'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :backend do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecm_audited_backend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Vasquez Angel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: Description of Ecm::Audited::Backend.
28
+ email:
29
+ - roberto@vasquez-angel.de
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - app/assets/javascripts/ecm/audited/backend/application.js
38
+ - app/assets/javascripts/ecm/audited/backend/application/dummy.js
39
+ - app/assets/javascripts/ecm_audited_backend.js
40
+ - app/assets/stylesheets/ecm/audited/backend/application.css
41
+ - app/assets/stylesheets/ecm/audited/backend/application/dummy.css
42
+ - app/assets/stylesheets/ecm_audited_backend.css
43
+ - app/controllers/concerns/controller/ecm/audited/audit_log_concern.rb
44
+ - app/controllers/ecm/audited/backend/application_controller.rb
45
+ - app/controllers/ecm/audited/backend/audit_logs_controller.rb
46
+ - app/controllers/ecm/audited/backend/home_controller.rb
47
+ - app/helpers/ecm/audited/backend/application_helper.rb
48
+ - app/views/ecm/audited/backend/audits/_index_extras.haml
49
+ - app/views/itsf/backend/resource/base/audit_log.haml
50
+ - app/views/layouts/ecm/audited/backend/application.html.erb
51
+ - config/initializers/assets.rb
52
+ - config/initializers/itsf_backend.rb
53
+ - config/locales/de.yml
54
+ - config/locales/en.yml
55
+ - config/routes.rb
56
+ - lib/ecm/audited/backend.rb
57
+ - lib/ecm/audited/backend/configuration.rb
58
+ - lib/ecm/audited/backend/engine.rb
59
+ - lib/ecm/audited/backend/version.rb
60
+ - lib/ecm_audited_backend.rb
61
+ - lib/tasks/ecm/audited/backend_tasks.rake
62
+ homepage: https://github.com/robotex82/ecm_audited_backend
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.5.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Summary of Ecm::Audited::Backend.
86
+ test_files: []