2013-01-25 19:18:17 +00:00
|
|
|
###
|
|
|
|
|
Setup read / write access
|
|
|
|
|
@param store
|
|
|
|
|
###
|
2013-02-05 05:20:58 +00:00
|
|
|
|
|
|
|
|
module.exports.customAccessControl = (store) ->
|
|
|
|
|
|
|
|
|
|
# store.readPathAccess "users.*", () -> # captures, next
|
|
|
|
|
# next = arguments[arguments.length-1]
|
|
|
|
|
# return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
# return next(true)
|
|
|
|
|
|
|
|
|
|
store.readPathAccess "users.*", -> # captures, next) ->
|
|
|
|
|
return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
console.log arguments
|
|
|
|
|
captures = arguments[0]
|
|
|
|
|
next = arguments[arguments.length - 1]
|
|
|
|
|
sameSession = captures is @session.userId
|
|
|
|
|
isServer = false #!this.req.socket; //TODO how to determine if request came from server, as in REST?
|
|
|
|
|
next sameSession or isServer
|
|
|
|
|
|
|
|
|
|
store.writeAccess "*", "users.*", -> # captures, value, next) ->
|
|
|
|
|
return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
[captures, next] = [arguments[0].split('.'), arguments[arguments.length-1]]
|
|
|
|
|
uid = captures.shift()
|
|
|
|
|
attrPath = captures.join('.') # new array shifted left, after shift() was run
|
|
|
|
|
|
|
|
|
|
# TODO the server can write to anything - aka, REST
|
|
|
|
|
#return next(true) if !this.req.socket;
|
|
|
|
|
|
|
|
|
|
# public access to users.*.party.invitation (TODO, lock down a bit more)
|
|
|
|
|
console.log attrPath
|
|
|
|
|
return next(true) if (attrPath == 'party.invitation')
|
|
|
|
|
|
|
|
|
|
# Same session (user.id = this.session.userId)
|
|
|
|
|
return next(true) if uid is @session.userId
|
|
|
|
|
|
|
|
|
|
next(false)
|
|
|
|
|
|
2013-01-25 19:18:17 +00:00
|
|
|
|
2013-01-27 15:05:15 +00:00
|
|
|
# store.writeAccess "*", "users.*.balance", (id, newBalance, next) ->
|
|
|
|
|
# return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
# purchasingSomethingOnClient = newBalance < this.session.req._racerModel.get("users.#{id}.balance")
|
|
|
|
|
# isServer = not @req.socket
|
|
|
|
|
# next(purchasingSomethingOnClient or isServer)
|
2013-01-25 19:18:17 +00:00
|
|
|
|
|
|
|
|
store.writeAccess "*", "users.*.flags.ads", -> # captures, value, next ->
|
|
|
|
|
return unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
next = arguments[arguments.length - 1]
|
|
|
|
|
isServer = not @req.socket
|
2013-01-30 20:57:36 +00:00
|
|
|
next(isServer)
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
Get user with API token
|
|
|
|
|
###
|
|
|
|
|
store.query.expose "users", "withIdAndToken", (id, api_token) ->
|
|
|
|
|
@where("id").equals(id)
|
|
|
|
|
.where('preferences.api_token').equals(api_token)
|
|
|
|
|
.limit(1)
|
|
|
|
|
|
|
|
|
|
store.queryAccess "users", "withIdAndToken", (id, token, next) ->
|
|
|
|
|
return next(false) unless @session and @session.userId # https://github.com/codeparty/racer/issues/37
|
|
|
|
|
isServer = not @req.socket
|
|
|
|
|
next(isServer)
|
2013-01-30 21:10:57 +00:00
|
|
|
|
|
|
|
|
###
|
|
|
|
|
Party permissions
|
|
|
|
|
###
|
2013-02-04 19:10:20 +00:00
|
|
|
store.query.expose "users", "party", (ids) ->
|
2013-01-30 21:10:57 +00:00
|
|
|
@where("id").within(ids)
|
2013-02-05 05:20:58 +00:00
|
|
|
.only('stats',
|
|
|
|
|
'items',
|
|
|
|
|
'party',
|
|
|
|
|
'preferences.gender',
|
|
|
|
|
'preferences.armorSet',
|
|
|
|
|
'auth.local.username',
|
|
|
|
|
'auth.facebook.displayName')
|
2013-01-30 21:10:57 +00:00
|
|
|
|
2013-02-04 19:10:20 +00:00
|
|
|
store.queryAccess "users", "party", (ids, next) ->
|
2013-01-30 21:10:57 +00:00
|
|
|
next(true) # no harm in public user stats
|
2013-02-05 05:20:58 +00:00
|
|
|
|
|
|
|
|
store.readPathAccess "parties.*", ->
|
|
|
|
|
arguments[arguments.length-1](true)
|
|
|
|
|
|
|
|
|
|
store.writeAccess "*", "parties.*", ->
|
|
|
|
|
arguments[arguments.length-1](true)
|