Class: ServicesController

Inherits:
ApplicationController
  • Object
show all
Includes:
PluginHelper
Defined in:
app/controllers/services_controller.rb

Constant Summary collapse

APP_CONFIG =

Load configuration items (MANDATORY, must be included)

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

Instance Method Summary collapse

Methods included from PluginHelper

#current_user, #get_current_user_role

Instance Method Details

#get_current_podio_userObject

Get current podio service account user Input Output



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/services_controller.rb', line 73

def get_current_podio_user
  begin

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

    serviceAccount = Metadata.first({ :conditions => [
        "key = ? and sites_id = ?", APP_CONFIG[:SERVICE_ACCOUNT_NAME], session[:accessible_appid]
    ]})

    if (!serviceAccount.nil?)
      render :json => { "status" => "success", "data" => serviceAccount.value.strip}
    else
      render :json => { "status" => "failure" }
    end
  rescue
    render :json => { "status" => "failure" }
  end
end

#get_current_podio_workspaceObject

Get current podio workspace Input Output



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/services_controller.rb', line 48

def get_current_podio_workspace
  begin

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

    curWorkspace = Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:PODIO_WORKSPACE], session[:accessible_appid]] })

    if (!curWorkspace.nil?)
      render :json => { "status" => "success", "data" => curWorkspace.value.to_s.strip }
    else
      render :json => { "status" => "failure" }
    end
  rescue
    render :json => { "status" => "failure" }
  end
end

#set_current_podio_workspaceObject

Set current podio workspace Input Output



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
# File 'app/controllers/services_controller.rb', line 14

def set_current_podio_workspace
  begin

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

    space = params[:space]
    metaId = Metadata.first({ :conditions => ['key = ? and sites_id = ?', APP_CONFIG[:PODIO_WORKSPACE], session[:accessible_appid]] });

    if (!metaId.nil?)
      Metadata.update(metaId, { :value => space })
    else
      Metadata.create({
                          :key => "currentWorkspace",
                          :value => space,
                          :mime => "plain/text",
                          :cat => "podio_config",
                          :sites_id => session[:accessible_appid]
                      }).save
    end

    render :json => { "status" => "success" }
  rescue
    render :json => { "status" => "failure", "message" => "Unable to set current podio workspace" }
  end
end

#update_or_create_podio_service_accountObject

Update or create podio service account Input from POST, POST Output json string



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/services_controller.rb', line 100

def 
  SymmetricEncryption.load!

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

  constServiceAccountInfoKey = APP_CONFIG[:SERVICE_ACCOUNT_NAME]
  constServiceAccountPassKey = APP_CONFIG[:SERVICE_ACCOUNT_PASS]

  podioUserObj = params[:userObject]
  podioPassObj = params[:passObject]

  begin
    fPodioUser = Metadata.where("key = ? and sites_id = ?", constServiceAccountInfoKey, session[:accessible_appid]).first
    fPodioPass = Metadata.where("key = ? and sites_id = ?", constServiceAccountPassKey, session[:accessible_appid]).first

    if (!fPodioUser.nil?)
      Metadata.update(fPodioUser.id, podioUserObj)
    else
      Metadata.create({
                          :key => constServiceAccountInfoKey,
                          :value => podioUserObj['value'],
                          :cat => podioUserObj['cat'],
                          :mime => podioUserObj['mime'],
                          :sites_id => session[:accessible_appid]
                      }).save!
    end

    if (!fPodioPass.nil?)
      podioPassObj['value'] = SymmetricEncryption.encrypt(podioPassObj['value'])
      Metadata.update(fPodioPass.id, podioPassObj)
    else
      Metadata.create({
                          :key => constServiceAccountPassKey,
                          :value => SymmetricEncryption.encrypt(podioPassObj['value']),
                          :cat => podioPassObj['cat'],
                          :mime => podioPassObj['mime'],
                          :sites_id => session[:accessible_appid]
                      }).save!
    end

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