Port to support postgresql.
This commit is contained in:
parent
70f5f21558
commit
ab63cfec4d
1 changed files with 23 additions and 23 deletions
|
@ -7,13 +7,13 @@ class RecentView < ApplicationModel
|
|||
after_update :notify_clients
|
||||
after_destroy :notify_clients
|
||||
|
||||
def self.log( object, o_id, user )
|
||||
def self.log(object, o_id, user)
|
||||
|
||||
# access check
|
||||
return if !access( object, o_id, user )
|
||||
return if !access(object, o_id, user)
|
||||
|
||||
# lookups
|
||||
object_lookup_id = ObjectLookup.by_name( object )
|
||||
object_lookup_id = ObjectLookup.by_name(object)
|
||||
|
||||
# create entry
|
||||
record = {
|
||||
|
@ -24,24 +24,24 @@ class RecentView < ApplicationModel
|
|||
RecentView.create(record)
|
||||
end
|
||||
|
||||
def self.log_destroy( requested_object, requested_object_id )
|
||||
def self.log_destroy(requested_object, requested_object_id)
|
||||
return if requested_object == 'RecentView'
|
||||
RecentView.where( recent_view_object_id: ObjectLookup.by_name( requested_object ) )
|
||||
.where( o_id: requested_object_id )
|
||||
RecentView.where(recent_view_object_id: ObjectLookup.by_name(requested_object))
|
||||
.where(o_id: requested_object_id)
|
||||
.destroy_all
|
||||
end
|
||||
|
||||
def self.user_log_destroy( user )
|
||||
RecentView.where( created_by_id: user.id ).destroy_all
|
||||
def self.user_log_destroy(user)
|
||||
RecentView.where(created_by_id: user.id).destroy_all
|
||||
end
|
||||
|
||||
def self.list( user, limit = 10, type = nil )
|
||||
def self.list(user, limit = 10, type = nil)
|
||||
recent_views = if !type
|
||||
RecentView.where( created_by_id: user.id )
|
||||
RecentView.where(created_by_id: user.id)
|
||||
.order('created_at DESC, id DESC')
|
||||
.limit(limit)
|
||||
else
|
||||
RecentView.select('DISTINCT(o_id), recent_view_object_id').where( created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type) )
|
||||
RecentView.select('DISTINCT(o_id), recent_view_object_id, created_at, id').where(created_by_id: user.id, recent_view_object_id: ObjectLookup.by_name(type))
|
||||
.order('created_at DESC, id DESC')
|
||||
.limit(limit)
|
||||
end
|
||||
|
@ -49,11 +49,11 @@ class RecentView < ApplicationModel
|
|||
list = []
|
||||
recent_views.each { |item|
|
||||
data = item.attributes
|
||||
data['object'] = ObjectLookup.by_id( data['recent_view_object_id'] )
|
||||
data.delete( 'recent_view_object_id' )
|
||||
data['object'] = ObjectLookup.by_id(data['recent_view_object_id'])
|
||||
data.delete('recent_view_object_id')
|
||||
|
||||
# access check
|
||||
next if !access( data['object'], data['o_id'], user )
|
||||
next if !access(data['object'], data['o_id'], user)
|
||||
|
||||
# add to result list
|
||||
list.push data
|
||||
|
@ -61,8 +61,8 @@ class RecentView < ApplicationModel
|
|||
list
|
||||
end
|
||||
|
||||
def self.list_full( user, limit = 10 )
|
||||
recent_viewed = list( user, limit )
|
||||
def self.list_full(user, limit = 10)
|
||||
recent_viewed = list(user, limit)
|
||||
|
||||
# get related object
|
||||
assets = ApplicationModel.assets_of_object_list(recent_viewed)
|
||||
|
@ -87,8 +87,8 @@ class RecentView < ApplicationModel
|
|||
|
||||
# check if object exists
|
||||
begin
|
||||
return if !Kernel.const_get( object )
|
||||
record = Kernel.const_get( object ).lookup( id: o_id )
|
||||
return if !Kernel.const_get(object)
|
||||
record = Kernel.const_get(object).lookup(id: o_id)
|
||||
return if !record
|
||||
rescue
|
||||
return
|
||||
|
@ -96,7 +96,7 @@ class RecentView < ApplicationModel
|
|||
|
||||
# check permission
|
||||
return if !record.respond_to?(:permission)
|
||||
record.permission( current_user: user )
|
||||
record.permission(current_user: user)
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
Loading…
Reference in a new issue