cozy-clearance
Helper package to manage clearances in cozy. This package include two parts:
- server side
- client side
Usage : Server Side
Base Module
clearance = require 'cozy-clearance' details = email:"steve@exemple.com"contactid:"3615"any:"other field"details2 = email:"jane@exemple.com"contactid:"3616"any:"other field"
The clearance.add function allows you to add a rule to a model
clearanceadd someModel'rw'details clearanceadd someModel'r'details2 consolelog someModelclearance# [ # {email:"steve@exemple.com", contactid:"3615", any:"other field", key:"secret", perm:"rw"} # {email:"jane@exemple.com", contactid:"3616", any:"other field", key:"secret2", perm:"rw"} # ]
The clearance.check function allows you to check a request against the model. It looks for the key in the request's querystring The callback is called with the matching rule if found, false otherwise
req.query.key = "secret"clearancecheck someModel'r'req # rule == {email:"steve@exemple.com", contactid:"3615", any:"other field", key:"secret", perm:"rw"} clearancecheck someModel'w'req # rule == false, steve doesn't have the 'w' permission
The clearance.revoke function allows you to revoke a rule for the model. All rules matching the given object will be revoked
clearancerevoke someModelemail:"steve@exemple.com" consolelog someModelclearance # [{email:"jane@exemple.com", contactid:"3616", any:"other field", key:"secret2", perm:"rw"}] # or clearancerevoke someModelany:"other field" consolelog someModelclearance # []
Controller :
To use the client side of cozy-clearance, you will need to expose some of the controller's routes.
# in routes.coffee clearance = require 'cozy-clearance' # use mailSubject & mailTemplate functions to customize the sent mail. clearanceCtl = clearancecontroller : # options.doc , options.url : # options.doc , options.url attachments: optional array of attachments 'docid': param: # fetch and save in req.doc 'clearance/contacts': get: clearanceCtlcontactList'clearance/contacts/:contactid': get: clearanceCtlcontact'clearance/contacts/:contactid.jpg': get: sharingcontactPicture'clearance/:docid' put: clearanceCtlchange'clearance/:docid/send': post: clearanceCtlsendAll
Usage : Client Side
Your client side environement should include the following :
- a global
require & require.define
, following the commonjs convention (like brunch) - a global
t
function that handles translations
Include the file client-build.js
or client-build.min.js
in your
vendor/scripts folder and use it like this :
CozyClearanceModal = require 'cozy-clearance/modal_share_view' model: someModel
You can override some methods :
# change the permissions method to add possible permissions : -> 'r': 'see this' 'rw': 'see and edit' 'rwy': 'see, edit and do Y' 'rwz': 'see, edit and do Z' # note : list all possible combinations, here, you can't have both Y & Z permissions
See cozy-files for heavy customization.
The contactCollection can be plugged to your app's realtime :
contactCollection = require 'cozy-clearance/contact_collection'= event # ... contactCollectionhandleRealtimeContactEvent event
Locales
The client-side library use the following locale keys:
- "cancel"
- "confirm"
- "copy paste link"
- "mail not send"
- "modal error"
- "modal ok"
- "modal question " + type + " shareable"
- "modal send mails
- "modal shared " + type + " custom msg"
- "modal shared public link msg"
- "modal shared with people msg"
- "no forgot"
- "no"
- "only you can see"
- "perm"
- "private"
- "r"
- "revoke"
- "save"
- "see link"
- "send email hint"
- "send mails question"
- "server error occured"
- "share confirm save"
- "share forgot add"
- "shared"
- "sharing"
- "yes forgot"
- "yes"
Contribute
Use coffeegulp to build the client side.
Use npm run build to build the server side
use npm test to run tests