rxcms-compliance_plugin 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +29 -0
  5. data/app/assets/javascripts/compliance_plugin/configure.js +147 -0
  6. data/app/assets/javascripts/compliance_plugin/index.js +3 -0
  7. data/app/assets/javascripts/compliance_plugin/installer.js +19 -0
  8. data/app/assets/javascripts/compliance_services.js +2 -0
  9. data/app/assets/stylesheets/compliance_engine.css +4 -0
  10. data/app/assets/stylesheets/compliance_installer.css +4 -0
  11. data/app/assets/stylesheets/compliance_services.css +4 -0
  12. data/app/controllers/compliance_engine_controller.rb +69 -0
  13. data/app/controllers/compliance_installer_controller.rb +91 -0
  14. data/app/controllers/compliance_services_controller.rb +86 -0
  15. data/app/helpers/compliance_engine_helper.rb +2 -0
  16. data/app/helpers/compliance_installer_helper.rb +2 -0
  17. data/app/helpers/compliance_plugin_helper.rb +30 -0
  18. data/app/helpers/compliance_services_helper.rb +2 -0
  19. data/app/views/compliance_engine/configure.html.erb +46 -0
  20. data/app/views/compliance_engine/index.html.erb +1 -0
  21. data/app/views/compliance_engine/installer.html.erb +7 -0
  22. data/config/compliance/compliance_config.yml +3 -0
  23. data/config/routes.rb +17 -0
  24. data/lib/rxcms-compliance_plugin/classes/compliance_operations.rb +218 -0
  25. data/lib/rxcms-compliance_plugin/classes/executor.rb +9 -0
  26. data/lib/rxcms-compliance_plugin/classes/status.rb +18 -0
  27. data/lib/rxcms-compliance_plugin/engine.rb +21 -0
  28. data/lib/rxcms-compliance_plugin/version.rb +3 -0
  29. data/lib/rxcms-compliance_plugin.rb +7 -0
  30. data/lib/tasks/rxcms-compliance_plugin_tasks.rake +4 -0
  31. metadata +219 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d126beb04ddef40a0b16b56d93b52867c35042c2
4
+ data.tar.gz: 201f47d9366cbc06124c462e9fba40ebf3c1235d
5
+ SHA512:
6
+ metadata.gz: 0d3ddffee0d989b330c391e45bed98ff54e18664ff99d436ac359ebcb072d2b5df8f3034cdb7005e506a69f390a1047e147347c14503ecc123a6ed0f2e0614d1
7
+ data.tar.gz: b6d5300fad750487f2ee58296abedcff337b2781b1f17eaeb139d50bff5058f9671f4f460c3a85910d10ac1409bad07b3d104b67a6f17b471ba7f4f4d291c516
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
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
+ = CompliancePlugin
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'RxcmsCompliancePlugin'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
@@ -0,0 +1,147 @@
1
+ function getComplianceFeatureStatus()
2
+ {
3
+ $.get("/compliance/services/feature/status", function(response){
4
+ if (response.status == "success")
5
+ {
6
+ if (response.data == "yes")
7
+ {
8
+ $("input[name=complianceFeature][value=on]").prop("checked",true);
9
+ } else if (response.data == "no")
10
+ {
11
+ $("input[name=complianceFeature][value=off]").prop("checked",true);
12
+ }
13
+ } else
14
+ {
15
+ Messenger().post("unable to get compliance feature status");
16
+ }
17
+ }).error(function(){
18
+ Messenger().post("unable to contact server");
19
+ });
20
+ }
21
+
22
+ function getVersioningFeatureStatus()
23
+ {
24
+ $.get("/compliance/services/feature/versioning/status", function(response){
25
+ if (response.status == "success")
26
+ {
27
+ if (response.data == "yes")
28
+ {
29
+ $("input[name=versioningFeature][value=on]").prop("checked",true);
30
+ $("input[name=complianceFeature]").removeAttr("disabled")
31
+ } else if (response.data == "no")
32
+ {
33
+ $("input[name=versioningFeature][value=off]").prop("checked",true);
34
+
35
+ $("input[name=complianceFeature]").attr("disabled","disabled");
36
+ $("input[name=complianceFeature][value=off]").prop("checked",true);
37
+ }
38
+ } else
39
+ {
40
+ Messenger().post("unable to get versioning feature status");
41
+ }
42
+ }).error(function(){
43
+ Messenger().post("unable to contact server");
44
+ });
45
+ }
46
+
47
+ $(function(){
48
+
49
+ Messenger.options = {
50
+ extraClasses: 'messenger-fixed messenger-on-bottom messenger-on-right',
51
+ theme: 'air'
52
+ };
53
+
54
+ // Automatically load compliance feature status on page load
55
+ getComplianceFeatureStatus();
56
+ getVersioningFeatureStatus();
57
+
58
+ // Track value of input[name=complianceFeature]
59
+ $("input[name=complianceFeature]").on("change", function(e){
60
+ e.stopPropagation();
61
+
62
+ var value = $(this).val() == "on" ? "yes" : "no";
63
+ var versioningValue = $("input[name=versioningFeature]:checked").val() == "on" ? "yes" : "no"
64
+
65
+ if (versioningValue == "no")
66
+ {
67
+ Messenger().post("versioning is required, please activate it");
68
+ return;
69
+ }
70
+
71
+ $("input[name=complianceFeature]").attr("disabled","disabled");
72
+ $.post("/compliance/services/feature/status/set",
73
+ {
74
+ "value" : value
75
+ }
76
+ ,function(response){
77
+ if (response.status == "success")
78
+ {
79
+ $("input[name=complianceFeature]").removeAttr("disabled");
80
+ Messenger().post("compliance status is set successfully");
81
+ } else
82
+ {
83
+ $("input[name=complianceFeature]").removeAttr("disabled");
84
+ Messenger().post("unable to set compliance feature status");
85
+ }
86
+ }).error(function(){
87
+ $("input[name=complianceFeature]").removeAttr("disabled");
88
+ Messenger().post("unable to contact server");
89
+ });
90
+ });
91
+
92
+ $("input[name=versioningFeature]").on("change", function(e){
93
+ e.stopPropagation();
94
+
95
+ var value = $(this).val() == "on" ? "yes" : "no";
96
+
97
+ if (value == "no")
98
+ {
99
+ $("input[name=complianceFeature][value=off]").prop("checked",true)
100
+ $("input[name=complianceFeature]").attr("disabled","disabled");
101
+ }
102
+ else if (value == "yes")
103
+ {
104
+ $("input[name=complianceFeature]").removeAttr("disabled");
105
+ }
106
+
107
+ $("input[name=versioningFeature]").attr("disabled","disabled");
108
+ $.post("/compliance/services/feature/versioning/status/set",
109
+ {
110
+ "value" : value
111
+ }, function(response){
112
+ if (response.status == "success")
113
+ {
114
+ $("input[name=versioningFeature]").removeAttr("disabled");
115
+ Messenger().post("versioning status is set successfully");
116
+ } else
117
+ {
118
+ $("input[name=versioningFeature]").removeAttr("disabled");
119
+ Messenger().post("unable to set versioning feature status");
120
+ }
121
+ }).error(function(){
122
+ $("input[name=versioningFeature]").removeAttr("disabled");
123
+ Messenger().post("unable to contact server");
124
+ });
125
+ });
126
+
127
+ // Uninstall
128
+ $("#uninstallBtn").on("click", function(){
129
+ var $this = $(this);
130
+ $this.attr("disabled","disabled");
131
+ $.post("/compliance/installer/uninstall", function(response){
132
+ if (response.status == "success")
133
+ {
134
+ Messenger().post("Successfully uninstalled, redirecting...");
135
+ location.reload();
136
+ }
137
+ else
138
+ {
139
+ $this.removeAttr("disabled");
140
+ Messenger().post("Unable to uninstall component");
141
+ }
142
+ }).error(function(){
143
+ Messenger().post("Unable to contact server");
144
+ $this.removeAttr("disabled");
145
+ })
146
+ });
147
+ });
@@ -0,0 +1,3 @@
1
+ $(function(){
2
+
3
+ });
@@ -0,0 +1,19 @@
1
+ $(function(){
2
+ // Automatically perform installation
3
+ $("#installationBtn").on("click", function(e){
4
+ e.stopPropagation();
5
+
6
+ $("#installationStatus").text("Installation process is under way, please wait...");
7
+ $.post("/compliance/installer/before_process", function(response){
8
+ if (response.status == "success")
9
+ {
10
+ location.reload();
11
+ } else
12
+ {
13
+ $("#installationStatus").text("Installation failed, please contact extension developer for more information!");
14
+ }
15
+ }).error(function(){
16
+ $("#installationStatus").text("Installation failed because the server is down. Please try again later");
17
+ });
18
+ });
19
+ });
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,69 @@
1
+ class ComplianceEngineController < ApplicationController
2
+ include CompliancePluginHelper
3
+
4
+ layout false
5
+
6
+ before_filter :get_current_user_role, :except => [
7
+ :index
8
+ ]
9
+
10
+ # Load configuration items (MANDATORY, must be included)
11
+ APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/compliance/compliance_config.yml', __FILE__))))
12
+
13
+ # Allow all to access index
14
+ # Disallow all to access configure and installer, except for admin
15
+
16
+ # Write your readme here
17
+ def index
18
+
19
+ end
20
+
21
+ def configure
22
+ # Check access
23
+ if (@curUserRole == 'contentadmin' ||
24
+ @curUserRole == 'user' ||
25
+ @curUserRole == 'loggedin' ||
26
+ @curUserRole == 'anonymous')
27
+ raise 'unauthorized access'
28
+ end
29
+
30
+ config = Metadata.first({ :conditions => ['sites_id = ? and cat = ? and key = ?', session[:accessible_appid], APP_CONFIG[:COMPLIANCE_CAT_CONFIG], APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG]]})
31
+
32
+ if (!defined?(PaperTrail))
33
+ raise 'paper_trail gem is required for this gem to work'
34
+ end
35
+
36
+ if (config.nil?)
37
+ raise 'configuration item for compliance plugin is not present'
38
+ end
39
+
40
+ if request.xhr?
41
+ respond_to do |t|
42
+ t.html
43
+ end
44
+ else
45
+ raise 'unauthorized access'
46
+ end
47
+ end
48
+
49
+ def installer
50
+ # Check access
51
+ if (@curUserRole == 'contentadmin' ||
52
+ @curUserRole == 'user' ||
53
+ @curUserRole == 'loggedin' ||
54
+ @curUserRole == 'anonymous')
55
+ raise 'unauthorized access'
56
+ end
57
+
58
+ if request.xhr?
59
+ respond_to do |t|
60
+ t.html
61
+ end
62
+ else
63
+ raise 'unauthorized access'
64
+ end
65
+ end
66
+
67
+ private
68
+
69
+ end
@@ -0,0 +1,91 @@
1
+ class ComplianceInstallerController < ApplicationController
2
+ include CompliancePluginHelper
3
+
4
+ layout false
5
+
6
+ before_filter :get_current_user_role
7
+
8
+ # Load configuration items (MANDATORY, must be included)
9
+ APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/compliance/compliance_config.yml', __FILE__))))
10
+
11
+ # Each step should return JSON status "success", "failure" or "unimplemented"
12
+
13
+ # Used for initializing and creating database entries
14
+ def before_process
15
+ SymmetricEncryption.load!
16
+
17
+ begin
18
+ # Check access
19
+ if (@curUserRole == 'contentadmin' ||
20
+ @curUserRole == 'user' ||
21
+ @curUserRole == 'loggedin' ||
22
+ @curUserRole == 'anonymous')
23
+ raise 'unauthorized access'
24
+ end
25
+
26
+ if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
27
+ Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
28
+ end
29
+ if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
30
+ Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
31
+ end
32
+
33
+ Metadata.create!({
34
+ :key => APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG],
35
+ :value => 'no',
36
+ :cat => APP_CONFIG[:COMPLIANCE_CAT_CONFIG],
37
+ :mime => "text/plain",
38
+ :sites_id => session[:accessible_appid]
39
+ })
40
+ Metadata.create!({
41
+ :key => APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG],
42
+ :value => 'no',
43
+ :cat => APP_CONFIG[:COMPLIANCE_CAT_CONFIG],
44
+ :mime => "text/plain",
45
+ :sites_id => session[:accessible_appid]
46
+ })
47
+
48
+ render :json => {:status => 'success'}
49
+ rescue Exception => ex
50
+ render :json => {:status => 'failure', :message => ex.message}
51
+ end
52
+ end
53
+
54
+ # Used for logical processing
55
+ def core_process
56
+ render :json => {:status => 'unimplemented'}
57
+ end
58
+
59
+ # Used for configuring data
60
+ def post_process
61
+ render :json => {:status => 'unimplemented'}
62
+ end
63
+
64
+ # Uninstaller
65
+ def uninstall
66
+ begin
67
+ # Check access
68
+ if (@curUserRole == 'contentadmin' ||
69
+ @curUserRole == 'user' ||
70
+ @curUserRole == 'loggedin' ||
71
+ @curUserRole == 'anonymous')
72
+ raise 'unauthorized access'
73
+ end
74
+
75
+ # Delete all configuration items
76
+ if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
77
+ Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
78
+ end
79
+ if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
80
+ Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
81
+ end
82
+
83
+ render :json => {:status => 'success'}
84
+ rescue Exception => ex
85
+ render :json => {:status => 'failure', :message => ex.message}
86
+ end
87
+ end
88
+
89
+ private
90
+
91
+ end
@@ -0,0 +1,86 @@
1
+ class ComplianceServicesController < ApplicationController
2
+ include CompliancePluginHelper
3
+
4
+ layout false
5
+
6
+ before_filter :get_current_user_role
7
+
8
+ # Load configuration items (MANDATORY, must be included)
9
+ APP_CONFIG = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/compliance/compliance_config.yml', __FILE__))))
10
+
11
+ # Get compliance feature status
12
+ def get_compliance_feature_status
13
+ begin
14
+
15
+ status = Metadata.first({ :conditions => ['sites_id = ? and key = ?', session[:accessible_appid], APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG]] })
16
+ if (!status.nil?)
17
+ render :json => { :status => 'success', :data => status.value }
18
+ else
19
+ raise "status doesn't exist"
20
+ end
21
+
22
+ rescue Exception => ex
23
+ render :json => { :status => 'failure', :message => ex.message }
24
+ end
25
+ end
26
+
27
+ def get_versioning_status
28
+ begin
29
+
30
+ status = Metadata.first({ :conditions => ['sites_id = ? and key = ?', session[:accessible_appid], APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG]] })
31
+ if (!status.nil?)
32
+ render :json => { :status => 'success', :data => status.value }
33
+ else
34
+ raise "status doesn't exist"
35
+ end
36
+
37
+ rescue Exception => ex
38
+ render :json => { :status => 'failure', :message => ex.message }
39
+ end
40
+ end
41
+
42
+ # Set compliance feature status
43
+ def set_compliance_feature_status
44
+ begin
45
+
46
+ status = Metadata.first({ :conditions => ['sites_id = ? and key = ?', session[:accessible_appid], APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG]] })
47
+ if (!status.nil?)
48
+ Metadata.update(status.id, { :value => params[:value] })
49
+ render :json => { :status => 'success' }
50
+ else
51
+ raise "compliance status doesn't exist"
52
+ end
53
+
54
+ rescue Exception => ex
55
+ render :json => { :status => 'failure', :message => ex.message }
56
+ end
57
+ end
58
+
59
+ def set_versioning_status
60
+ begin
61
+
62
+ status = Metadata.first({ :conditions => ['sites_id = ? and key = ?', session[:accessible_appid], APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG]] })
63
+ if (!status.nil?)
64
+ if (params[:value] == 'no')
65
+ Metadata.paper_trail_off
66
+ complianceStatus = Metadata.first({ :conditions => ['sites_id = ? and key = ?', session[:accessible_appid], APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG]] })
67
+ if (!complianceStatus.nil?)
68
+ Metadata.update(complianceStatus.id, { :value => 'no' })
69
+ end
70
+ else
71
+ Metadata.paper_trail_on
72
+ end
73
+ Metadata.update(status.id, { :value => params[:value] })
74
+ render :json => { :status => 'success' }
75
+ else
76
+ raise "versioning status doesn't exist"
77
+ end
78
+
79
+ rescue Exception => ex
80
+ render :json => { :status => 'failure', :message => ex.message }
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ end
@@ -0,0 +1,2 @@
1
+ module ComplianceEngineHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ComplianceInstallerHelper
2
+ end
@@ -0,0 +1,30 @@
1
+ module CompliancePluginHelper
2
+
3
+ def current_user
4
+ if UserSession.find.nil?
5
+ @current_user ||= nil
6
+ else
7
+ @current_user ||= User.find(UserSession.find.record.id)
8
+ end
9
+ end
10
+
11
+ # Get current user's role
12
+ def get_current_user_role
13
+ @current_user = current_user
14
+ if (!@current_user.nil?)
15
+ siteId = session[:accessible_appid]
16
+ roleId = session[:accessible_roleid]
17
+
18
+ if (!siteId.nil? && !roleId.nil?)
19
+ userRole = Role.find(roleId)
20
+ @curUserRole = userRole.name
21
+ else
22
+ @curUserRole = 'loggedin'
23
+ end
24
+
25
+ else
26
+ @curUserRole = 'anonymous'
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,2 @@
1
+ module ComplianceServicesHelper
2
+ end
@@ -0,0 +1,46 @@
1
+ <div class="container">
2
+ <ul id="complianceConfigureTabs" class="nav nav-tabs">
3
+ <li class="active"><a href="#configure" data-toggle="tab">Configuration</a></li>
4
+ <li><a href="#uninstall" data-toggle="tab">Uninstall</a></li>
5
+ </ul>
6
+
7
+ <div id="myTabContent" class="tab-content">
8
+
9
+ <div class="tab-pane fade in active" id="configure">
10
+ <div class="row-fluid">
11
+ <div class="span3">
12
+ <div style="margin:5px;">
13
+ <h5>Compliance Feature</h5>
14
+ <label for="complianceFeatureOn">
15
+ <input type="radio" name="complianceFeature" id="complianceFeatureOn" value="on" disabled="disabled" /> on
16
+ </label>
17
+ <label for="complianceFeatureOff">
18
+ <input type="radio" name="complianceFeature" id="complianceFeatureOff" value="off" disabled="disabled" /> off
19
+ </label>
20
+ </div>
21
+ </div>
22
+
23
+ <div class="span3">
24
+ <div style="margin:5px;">
25
+ <h5>Versioning Feature</h5>
26
+ <label for="complianceFeatureOn">
27
+ <input type="radio" name="versioningFeature" id="versioningFeatureOn" value="on" /> on
28
+ </label>
29
+ <label for="complianceFeatureOff">
30
+ <input type="radio" name="versioningFeature" id="versioningFeatureOff" value="off" /> off
31
+ </label>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+
37
+ <div class="tab-pane fade" id="uninstall">
38
+ <div>
39
+ <button id="uninstallBtn" type="button" class="btn btn-danger">Uninstall</button>
40
+ </div>
41
+ </div>
42
+
43
+ </div>
44
+ </div>
45
+
46
+ <%= javascript_include_tag "compliance_plugin/configure" %>
@@ -0,0 +1 @@
1
+ <h1>This is the readme page of Alliance CMS Compliance Plugin</h1>
@@ -0,0 +1,7 @@
1
+ <div class="container">
2
+ <div style="text-align:center;margin:64px 0 0 0;">
3
+ <h4 id="installationStatus">Click <a id="installationBtn" href="javascript:void(0);">here</a> to install</h4>
4
+ </div>
5
+ </div>
6
+
7
+ <%= javascript_include_tag "compliance_plugin/installer" %>
@@ -0,0 +1,3 @@
1
+ COMPLIANCE_ACTIVATION_CONFIG : complianceActivationConfig
2
+ COMPLIANCE_VERSIONING_ACTIVATION_CONFIG : complianceVersioningActivationConfig
3
+ COMPLIANCE_CAT_CONFIG : compliance_config
data/config/routes.rb ADDED
@@ -0,0 +1,17 @@
1
+ Rails.application.routes.draw do
2
+
3
+ get "/compliance/engine/readme" => "compliance_engine#index"
4
+ get "/compliance/engine/configure" => "compliance_engine#configure"
5
+ get "/compliance/engine/installer" => "compliance_engine#installer"
6
+
7
+ post "/compliance/installer/before_process" => "compliance_installer#before_process"
8
+ post "/compliance/installer/core_process" => "compliance_installer#core_process"
9
+ post "/compliance/installer/post_process" => "compliance_installer#post_process"
10
+ post "/compliance/installer/uninstall" => "compliance_installer#uninstall"
11
+
12
+ # Services
13
+ get "/compliance/services/feature/status" => "compliance_services#get_compliance_feature_status"
14
+ get "/compliance/services/feature/versioning/status" => "compliance_services#get_versioning_status"
15
+ post "/compliance/services/feature/status/set" => "compliance_services#set_compliance_feature_status"
16
+ post "/compliance/services/feature/versioning/status/set" => "compliance_services#set_versioning_status"
17
+ end
@@ -0,0 +1,218 @@
1
+ module RxcmsCompliancePlugin
2
+
3
+ class ComplianceOperations
4
+ # Used for enforcing compliance of metadata
5
+
6
+ def self.process_content(siteid, obj)
7
+ if (getFeatureStatus(siteid, 'compliance') == "yes")
8
+ if (!obj.nil?)
9
+ if (obj.archived?)
10
+ raise
11
+ end
12
+
13
+ release = Release.find_by_metadata_id(obj.id)
14
+ if (release.nil?)
15
+ raise
16
+ else
17
+ # check versions and return the right content
18
+ if (release.date_time.nil?)
19
+ else
20
+ obj = obj.version_at(release.date_time)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ return obj
27
+ end
28
+
29
+ def self.process_content_with_flag(siteid, obj)
30
+ cFlag = true
31
+ if (getFeatureStatus(siteid, 'compliance') == "yes")
32
+ if (!obj.nil?)
33
+ if (obj.archived?)
34
+ cFlag = false
35
+ else
36
+ release = Release.find_by_metadata_id(obj.id)
37
+ if (release.nil?)
38
+ cFlag = false
39
+ else
40
+ # check versions and return the right content
41
+ if (release.date_time.nil?)
42
+ else
43
+ obj = obj.version_at(release.date_time)
44
+ end
45
+ end
46
+ end
47
+ else
48
+
49
+ end
50
+ end
51
+
52
+ return { :data => obj, :flag => cFlag }
53
+ end
54
+
55
+ def self.create
56
+ # Do nothing
57
+ end
58
+
59
+ def self.update(id, dataObj, current_user_id, affectedCategory, siteid, time)
60
+ status = getFeatureStatus(siteid, 'compliance')
61
+ versioningStatus = getFeatureStatus(siteid, 'versioning')
62
+
63
+ if (!status.nil? && !versioningStatus.nil?)
64
+
65
+ if (versioningStatus == "yes")
66
+ #---
67
+ Metadata.paper_trail_on
68
+ if (status == "yes")
69
+ if (affectedCategory.include?(Metadata.find(id.to_i).cat))
70
+ Metadata.update(id, dataObj)
71
+
72
+ if (time != "current")
73
+ # Allow update changes but doesn't allow publishing
74
+ modifier = Version.select("whodunnit").where("created_at >= ? and created_at <= ?", DateTime.parse(time) - 1.second, DateTime.parse(time) + 1.second).first()
75
+
76
+ if (modifier[:whodunnit].to_i != current_user_id)
77
+ release = Release.first({:conditions => ['metadata_id = ?', id]})
78
+ if (!release.nil?)
79
+ release.destroy
80
+ end
81
+ Release.create({
82
+ :metadata_id => id,
83
+ :date_time => DateTime.parse(time),
84
+ :users_id => current_user_id
85
+ })
86
+ else
87
+ raise "own-change"
88
+ end
89
+ else
90
+ # raise "the content is current"
91
+ release = Release.first({:conditions => ['metadata_id = ?', id]})
92
+ if (!release.nil?)
93
+ if (release.users_id != current_user_id)
94
+ release.destroy
95
+ Release.create({
96
+ :metadata_id => id,
97
+ :date_time => DateTime.now,
98
+ :users_id => current_user_id
99
+ })
100
+ else
101
+ raise "own-change"
102
+ end
103
+ else
104
+ Release.create({
105
+ :metadata_id => id,
106
+ :date_time => DateTime.now,
107
+ :users_id => current_user_id
108
+ })
109
+ end
110
+
111
+ end
112
+
113
+ return "saved_published"
114
+ else
115
+ # if not in affected category, should not be tracking
116
+ Metadata.update(id, dataObj)
117
+ end
118
+ else
119
+ raise "fallback"
120
+ end
121
+ #---
122
+ else
123
+ # raise "versioning feature status is not found"
124
+ Metadata.paper_trail_off
125
+ Metadata.update(id, dataObj)
126
+ return "saved"
127
+ end
128
+
129
+ else
130
+ # raise "compliance feature bundle status is not found"
131
+ Metadata.paper_trail_off
132
+ Metadata.update(id, dataObj)
133
+ return "saved"
134
+ end
135
+
136
+ end
137
+
138
+ def self.destroy(siteid, affectedCategory, metadata)
139
+ versioningStatus = getFeatureStatus(siteid, 'versioning')
140
+
141
+ if (!versioningStatus.nil?)
142
+ if (versioningStatus == "yes")
143
+ if (affectedCategory.include?(metadata.cat))
144
+ metadata.archived = true
145
+ metadata.save
146
+ else
147
+ Metadata.paper_trail_on
148
+ metadata.destroy
149
+ end
150
+ else
151
+ Metadata.paper_trail_off
152
+ metadata.destroy
153
+ end
154
+ else
155
+ Metadata.paper_trail_off
156
+ metadata.destroy
157
+ end
158
+
159
+ end
160
+
161
+ def self.destroy_permanently(id)
162
+ begin
163
+ # Destroy item in metadata
164
+ metadata = Metadata.first({ :conditions => ['id = ?', id] })
165
+ if (!metadata.nil?)
166
+ Metadata.paper_trail_off
167
+ metadata.destroy
168
+ end
169
+
170
+ release = Release.first({ :conditions => ['metadata_id = ?', id]})
171
+ if (!release.nil?)
172
+ release.destroy
173
+ end
174
+
175
+ # And, destroy item in versions
176
+ Version.destroy_all(:item_id => id)
177
+
178
+ rescue Exception => ex
179
+ raise ex.message
180
+ end
181
+ end
182
+
183
+ def self.restore(id)
184
+ begin
185
+ item = Metadata.find(id)
186
+ item.archived = false
187
+ item.save
188
+ rescue Exception => ex
189
+ raise ex.message
190
+ end
191
+ end
192
+
193
+ def self.getFeatureStatus(siteid, type)
194
+ app_config = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../../config/compliance/compliance_config.yml', __FILE__))))
195
+
196
+ if (type == 'compliance')
197
+ status = Metadata.first({:conditions => ['sites_id = ? and key = ?', siteid, app_config[:COMPLIANCE_ACTIVATION_CONFIG]]})
198
+ if (!status.nil?)
199
+ return status.value
200
+ else
201
+ return nil
202
+ end
203
+ elsif (type == 'versioning')
204
+ status = Metadata.first({:conditions => ['sites_id = ? and key = ?', siteid, app_config[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG]]})
205
+ if (!status.nil?)
206
+ return status.value
207
+ else
208
+ return nil
209
+ end
210
+ else
211
+ return nil
212
+ end
213
+ end
214
+
215
+ private_class_method :getFeatureStatus
216
+ end
217
+
218
+ end
@@ -0,0 +1,9 @@
1
+ module RxcmsCompliancePlugin
2
+
3
+ class Executor
4
+ # def self.execute(placeholder, attrs, exts)
5
+ # return ''
6
+ # end
7
+ end
8
+
9
+ end
@@ -0,0 +1,18 @@
1
+ module RxcmsCompliancePlugin
2
+
3
+ class Status
4
+
5
+ def self.isEnabled?(siteid)
6
+ app_config = HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../../config/compliance/compliance_config.yml', __FILE__))))
7
+
8
+ tHash = Hash.new
9
+
10
+ tHash['compliance'] = Metadata.first({:conditions => ['sites_id = ? and key = ?', siteid, app_config[:COMPLIANCE_ACTIVATION_CONFIG]]}).value
11
+ tHash['versioning'] = Metadata.first({:conditions => ['sites_id = ? and key = ?', siteid, app_config[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG]]}).value
12
+
13
+ return tHash
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'flag_shih_tzu'
3
+ require 'paper_trail'
4
+
5
+ module RxcmsCompliancePlugin
6
+ extend ::ActiveSupport::Autoload
7
+
8
+ autoload :PaperTrail
9
+ autoload :FlagShihTzu
10
+
11
+ class Engine < ::Rails::Engine
12
+
13
+ config.generators do |g|
14
+ g.test_framework :rspec
15
+ # g.fixture_replacement :factory_girl, :dir => 'spec/factories'
16
+ end
17
+
18
+ config.autoload_paths += Dir["#{config.root}/lib/rxcms-compliance_plugin/classes/**/"]
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module RxcmsCompliancePlugin
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "rxcms-compliance_plugin/engine"
2
+
3
+ module RxcmsCompliancePlugin
4
+ require "rxcms-compliance_plugin/classes/executor"
5
+ require "rxcms-compliance_plugin/classes/compliance_operations"
6
+ require "rxcms-compliance_plugin/classes/status"
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :compliance_plugin do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rxcms-compliance_plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Anh Nguyen
8
+ - Julian Cowan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 3.2.13
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 3.2.13
28
+ - !ruby/object:Gem::Dependency
29
+ name: sqlite3
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: mysql2
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: pg
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: paper_trail
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 3.0.0.beta1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 3.0.0.beta1
84
+ - !ruby/object:Gem::Dependency
85
+ name: flag_shih_tzu
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: sqlite3
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: paper_trail
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 3.0.0.beta1
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 3.0.0.beta1
126
+ - !ruby/object:Gem::Dependency
127
+ name: flag_shih_tzu
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rspec-rails
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ description: Plugin Extension for RXCMS that provides versioning and peer review capability
155
+ for all content.
156
+ email:
157
+ - rxcms@ngonluakiko.com
158
+ executables: []
159
+ extensions: []
160
+ extra_rdoc_files: []
161
+ files:
162
+ - app/views/compliance_engine/configure.html.erb
163
+ - app/views/compliance_engine/installer.html.erb
164
+ - app/views/compliance_engine/index.html.erb
165
+ - app/controllers/compliance_installer_controller.rb
166
+ - app/controllers/compliance_services_controller.rb
167
+ - app/controllers/compliance_engine_controller.rb
168
+ - app/assets/javascripts/compliance_services.js
169
+ - app/assets/javascripts/compliance_plugin/installer.js
170
+ - app/assets/javascripts/compliance_plugin/index.js
171
+ - app/assets/javascripts/compliance_plugin/configure.js
172
+ - app/assets/stylesheets/compliance_services.css
173
+ - app/assets/stylesheets/compliance_installer.css
174
+ - app/assets/stylesheets/compliance_engine.css
175
+ - app/helpers/compliance_services_helper.rb
176
+ - app/helpers/compliance_plugin_helper.rb
177
+ - app/helpers/compliance_installer_helper.rb
178
+ - app/helpers/compliance_engine_helper.rb
179
+ - config/compliance/compliance_config.yml
180
+ - config/routes.rb
181
+ - lib/rxcms-compliance_plugin/classes/compliance_operations.rb
182
+ - lib/rxcms-compliance_plugin/classes/executor.rb
183
+ - lib/rxcms-compliance_plugin/classes/status.rb
184
+ - lib/rxcms-compliance_plugin/engine.rb
185
+ - lib/rxcms-compliance_plugin/version.rb
186
+ - lib/rxcms-compliance_plugin.rb
187
+ - lib/tasks/rxcms-compliance_plugin_tasks.rake
188
+ - MIT-LICENSE
189
+ - Rakefile
190
+ - README.rdoc
191
+ homepage: https://bitbucket.org/kikoflame/rxcms-compliance-plugin
192
+ licenses:
193
+ - MIT
194
+ metadata:
195
+ compatCode: 2dd89a9ecdeb920d539954fd9fb3da7de9f52a61ee9895d06e4bc1bab11a598b
196
+ fullName: Compliance Plugin
197
+ mountPoint: /compliance/engine/configure
198
+ installerPoint: /compliance/engine/installer
199
+ post_install_message:
200
+ rdoc_options: []
201
+ require_paths:
202
+ - lib
203
+ required_ruby_version: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - '>='
206
+ - !ruby/object:Gem::Version
207
+ version: '0'
208
+ required_rubygems_version: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - '>='
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
213
+ requirements: []
214
+ rubyforge_project:
215
+ rubygems_version: 2.0.6
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Versioning and peer review capability.
219
+ test_files: []