Class: ComplianceInstallerController

Inherits:
ApplicationController
  • Object
show all
Includes:
CompliancePluginHelper
Defined in:
app/controllers/compliance_installer_controller.rb

Constant Summary collapse

APP_CONFIG =

Load configuration items (MANDATORY, must be included)

HashWithIndifferentAccess.new(YAML.load(File.read(File.expand_path('../../../config/compliance/compliance_config.yml', __FILE__))))

Instance Method Summary collapse

Methods included from CompliancePluginHelper

#current_user, #get_current_user_role

Instance Method Details

#before_processObject

Used for initializing and creating database entries



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/compliance_installer_controller.rb', line 14

def before_process
  SymmetricEncryption.load!

  begin
    # Check access
    if (@curUserRole == 'contentadmin' ||
        @curUserRole == 'user' ||
        @curUserRole == 'loggedin' ||
        @curUserRole == 'anonymous')
      raise 'unauthorized access'
    end

    if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
      Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
    end
    if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
      Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
    end

    Metadata.create!({
                         :key => APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG],
                         :value => 'no',
                         :cat => APP_CONFIG[:COMPLIANCE_CAT_CONFIG],
                         :mime => "text/plain",
                         :sites_id => session[:accessible_appid]
                     })
    Metadata.create!({
                         :key => APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG],
                         :value => 'no',
                         :cat => APP_CONFIG[:COMPLIANCE_CAT_CONFIG],
                         :mime => "text/plain",
                         :sites_id => session[:accessible_appid]
                     })

    render :json => {:status => 'success'}
  rescue Exception => ex
    render :json => {:status => 'failure', :message => ex.message}
  end
end

#core_processObject

Used for logical processing



55
56
57
# File 'app/controllers/compliance_installer_controller.rb', line 55

def core_process
  render :json => {:status => 'unimplemented'}
end

#post_processObject

Used for configuring data



60
61
62
# File 'app/controllers/compliance_installer_controller.rb', line 60

def post_process
  render :json => {:status => 'unimplemented'}
end

#uninstallObject

Uninstaller



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/controllers/compliance_installer_controller.rb', line 65

def uninstall
  begin
    # Check access
    if (@curUserRole == 'contentadmin' ||
        @curUserRole == 'user' ||
        @curUserRole == 'loggedin' ||
        @curUserRole == 'anonymous')
      raise 'unauthorized access'
    end

    # Delete all configuration items
    if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
      Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
    end
    if !Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).nil?
      Metadata.first({:conditions => ['key = ? and sites_id = ?', APP_CONFIG[:COMPLIANCE_VERSIONING_ACTIVATION_CONFIG], session[:accessible_appid]]}).destroy
    end

    render :json => {:status => 'success'}
  rescue Exception => ex
    render :json => {:status => 'failure', :message => ex.message}
  end
end