Class: SharingServicesController

Inherits:
ApplicationController
  • Object
show all
Includes:
SharingPluginHelper
Defined in:
app/controllers/sharing_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/sharing/sharing_config.yml', __FILE__))))

Instance Method Summary collapse

Methods included from SharingPluginHelper

#current_user, #get_current_user_role

Instance Method Details

#get_release_sharedObject



35
36
37
38
39
40
41
# File 'app/controllers/sharing_services_controller.rb', line 35

def get_release_shared
  begin
    render :json => { :status => 'success', :data => Release.(params[:id]).nil? ? nil : Release.(params[:id]).scope }
  rescue Exception => ex
    render :json => { :status => 'failure', :message => "unable to process your request" }
  end
end

#get_shared_item_contentObject



57
58
59
60
61
62
63
# File 'app/controllers/sharing_services_controller.rb', line 57

def get_shared_item_content
  begin
    render :json => { :status => 'success', :data => Metadata.find(params[:id]).value }
  rescue Exception => ex
    render :json => { :status => 'failure', :message => "unable to process your request" }
  end
end

#get_shared_releasesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/sharing_services_controller.rb', line 43

def get_shared_releases
  begin
    limit = params[:limit].to_i
    offset = params[:offset].to_i

    render :json => { :status => 'success', :data => Release.select("metadata.id, key, cat, value, login as name")
                                                            .joins("INNER JOIN metadata on metadata.id = releases.metadata_id")
                                                            .joins("INNER JOIN users on users.id = releases.users_id")
                                                            .where("scope <> ? and users_id <> ?", "w", UserSession.find.record.id).offset(offset).limit(limit) }
  rescue Exception => ex
    render :json => { :status => 'failure', :message => "unable to process your request" }
  end
end

#set_release_sharedObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/sharing_services_controller.rb', line 16

def set_release_shared
  begin
    item = Release.(params[:id].to_i)
    if (item.nil?)
      render :json => { :status => 'failure', :message => 'element has not been released yet' }
    else
      if (UserSession.find.record.id != item.users_id)
        render :json => { :status => 'failure', :message => "item sharing setings hasn't been changed because you are not the last publisher" }
      else
        Release.update(item.id, { :scope => params[:shared] })
        render :json => { :status => 'success' }
      end
    end
  rescue Exception => ex
    # render :json => { :status => 'failure', :message => ex.message }
    render :json => { :status => 'failure', :message => "unable to process your request" }
  end
end