{"action":"created","issue":{"url":"https://api.github.com/repos/ciroreed/krasny-server/issues/1","repository_url":"https://api.github.com/repos/ciroreed/krasny-server","labels_url":"https://api.github.com/repos/ciroreed/krasny-server/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/ciroreed/krasny-server/issues/1/comments","events_url":"https://api.github.com/repos/ciroreed/krasny-server/issues/1/events","html_url":"https://github.com/ciroreed/krasny-server/issues/1","id":129616747,"number":1,"title":"instead of regular joins, use predicate functions to filter results (more options)","user":{"login":"ciroreed","id":6052309,"avatar_url":"https://avatars.githubusercontent.com/u/6052309?v=3","gravatar_id":"","url":"https://api.github.com/users/ciroreed","html_url":"https://github.com/ciroreed","followers_url":"https://api.github.com/users/ciroreed/followers","following_url":"https://api.github.com/users/ciroreed/following{/other_user}","gists_url":"https://api.github.com/users/ciroreed/gists{/gist_id}","starred_url":"https://api.github.com/users/ciroreed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciroreed/subscriptions","organizations_url":"https://api.github.com/users/ciroreed/orgs","repos_url":"https://api.github.com/users/ciroreed/repos","events_url":"https://api.github.com/users/ciroreed/events{/privacy}","received_events_url":"https://api.github.com/users/ciroreed/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ciroreed/krasny-server/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-28T23:28:59Z","updated_at":"2016-02-06T11:32:08Z","closed_at":null,"body":"For more functionality we must define a property called \"crud\". \r\n\r\n\"crud\" property stands for predicates or procedures that server must execute before any operation\r\n\r\nIE: \r\n```javascript\r\ncrud: {\r\n        read: function (incidence, session) {\r\n          return session.id === incidence.owner || session.perm > incidence.permissionLevel;\r\n        },\r\n        create: function(incidence, session){\r\n          if(session.perm === 0){\r\n            incidence.owner = session.id\r\n            return incidence;\r\n          }\r\n          return false;\r\n        }\r\n      }\r\n```\r\n\r\nWe want to define a predicate in order to filter which incidences can read an user, by default an user can read the incidences that own, then .. if the user has permissions to see it (because of level permissions)\r\n\r\nFor creating an incidence we check if permission level of session object is equal to 0 meaning this is a regular user which is allow to create new incidences, other users can only read, etc (this is an example). If permission match 0 we modify the incidence property \"owner\" with the id of the session meaning that he is the owner. If perm <> 0 we return false meaning that server must return 401 code."},"comment":{"url":"https://api.github.com/repos/ciroreed/krasny-server/issues/comments/180740997","html_url":"https://github.com/ciroreed/krasny-server/issues/1#issuecomment-180740997","issue_url":"https://api.github.com/repos/ciroreed/krasny-server/issues/1","id":180740997,"user":{"login":"ciroreed","id":6052309,"avatar_url":"https://avatars.githubusercontent.com/u/6052309?v=3","gravatar_id":"","url":"https://api.github.com/users/ciroreed","html_url":"https://github.com/ciroreed","followers_url":"https://api.github.com/users/ciroreed/followers","following_url":"https://api.github.com/users/ciroreed/following{/other_user}","gists_url":"https://api.github.com/users/ciroreed/gists{/gist_id}","starred_url":"https://api.github.com/users/ciroreed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciroreed/subscriptions","organizations_url":"https://api.github.com/users/ciroreed/orgs","repos_url":"https://api.github.com/users/ciroreed/repos","events_url":"https://api.github.com/users/ciroreed/events{/privacy}","received_events_url":"https://api.github.com/users/ciroreed/received_events","type":"User","site_admin":false},"created_at":"2016-02-06T11:32:08Z","updated_at":"2016-02-06T11:32:08Z","body":"read function is a predicate, other functions as create, update or delete are conditions"}}