{"action":"created","comment":{"url":"https://api.github.com/repos/cozy/cozy-data-system/pulls/comments/25692367","id":25692367,"diff_hunk":"@@ -98,39 +102,157 @@ recoverDesignDocs = (callback) =>\n         startkey: \"_design/\"\n         endkey: \"_design0\"\n     db.all filterRange, (err, res) =>\n+        return callback err if err?\n         recoverDocs res, [], callback\n \n+\n+# Data system uses some views, this function initialize it.\n+initializeDSView = (callback) ->\n+    views =\n+        # Usefull for function 'doctypes' (controller/request. Databrowser)\n+        doctypes:\n+            all:\n+                map: \"\"\"\n+                function(doc) {\n+                    if(doc.docType) {\n+                        return emit(doc.docType, null);\n+                    }\n+                }\n+                \"\"\"\n+                # use to make a \"distinct\"\n+                reduce: \"\"\"\n+                function(key, values) {\n+                    return true;\n+                }\n+                \"\"\"\n+        # Usefull to manage device access\n+        device:\n+            all:\n+                map: \"\"\"\n+                function(doc) {\n+                    if(doc.docType && doc.docType.toLowerCase() === \"device\") {\n+                        return emit(doc._id, doc);\n+                    }\n+                }\n+                \"\"\"\n+            byLogin:\n+                map: \"\"\"\n+                function (doc) {\n+                    if(doc.docType && doc.docType.toLowerCase() === \"device\") {\n+                        return emit(doc.login, doc)\n+                    }\n+                }\n+                \"\"\"\n+        # Usefull to remove binary lost\n+        binary:\n+            all:\n+                map: \"\"\"\n+                function(doc) {\n+                    if(doc.docType && doc.docType.toLowerCase() === \"binary\") {\n+                        emit(doc._id, null);\n+                    }\n+                }\n+                \"\"\"\n+            byDoc:\n+                map: \"\"\"\n+                function(doc) {\n+                    if(doc.binary) {\n+                        for (bin in doc.binary) {\n+                            emit(doc.binary[bin].id, doc._id);\n+                        }\n+                    }\n+                }\n+                \"\"\"\n+        # Usefull for API tags\n+        tags:\n+            all:\n+                map: \"\"\"\n+                function (doc) {\n+                var _ref;\n+                return (_ref = doc.tags) != null ? typeof _ref.forEach === \"function\" ? _ref.forEach(function(tag) {\n+                   return emit(tag, null);\n+                    }) : void 0 : void 0;\n+                }\n+                \"\"\"\n+                # use to make a \"distinct\"\n+                reduce: \"\"\"\n+                function(key, values) {\n+                    return true;\n+                }\n+                \"\"\"\n+    async.forEach Object.keys(views), (docType, cb) ->\n+        view = views[docType]\n+        db.get \"_design/#{docType}\", (err, doc) ->\n+            if err and err.error is 'not_found'\n+                db.save \"_design/#{docType}\", view, cb\n+            else","path":"server/lib/request.coffee","position":129,"original_position":129,"commit_id":"e450c8c05ceed59473a722b45bfd0849422c550e","original_commit_id":"e450c8c05ceed59473a722b45bfd0849422c550e","user":{"login":"aenario","id":1580287,"avatar_url":"https://avatars.githubusercontent.com/u/1580287?v=3","gravatar_id":"","url":"https://api.github.com/users/aenario","html_url":"https://github.com/aenario","followers_url":"https://api.github.com/users/aenario/followers","following_url":"https://api.github.com/users/aenario/following{/other_user}","gists_url":"https://api.github.com/users/aenario/gists{/gist_id}","starred_url":"https://api.github.com/users/aenario/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aenario/subscriptions","organizations_url":"https://api.github.com/users/aenario/orgs","repos_url":"https://api.github.com/users/aenario/repos","events_url":"https://api.github.com/users/aenario/events{/privacy}","received_events_url":"https://api.github.com/users/aenario/received_events","type":"User","site_admin":false},"body":"else if err","created_at":"2015-03-03T14:50:41Z","updated_at":"2015-03-03T14:50:41Z","html_url":"https://github.com/cozy/cozy-data-system/pull/125#discussion_r25692367","pull_request_url":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125","_links":{"self":{"href":"https://api.github.com/repos/cozy/cozy-data-system/pulls/comments/25692367"},"html":{"href":"https://github.com/cozy/cozy-data-system/pull/125#discussion_r25692367"},"pull_request":{"href":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125"}}},"pull_request":{"url":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125","id":30058589,"html_url":"https://github.com/cozy/cozy-data-system/pull/125","diff_url":"https://github.com/cozy/cozy-data-system/pull/125.diff","patch_url":"https://github.com/cozy/cozy-data-system/pull/125.patch","issue_url":"https://api.github.com/repos/cozy/cozy-data-system/issues/125","number":125,"state":"open","locked":false,"title":"Binary cleaning","user":{"login":"poupotte","id":2659119,"avatar_url":"https://avatars.githubusercontent.com/u/2659119?v=3","gravatar_id":"","url":"https://api.github.com/users/poupotte","html_url":"https://github.com/poupotte","followers_url":"https://api.github.com/users/poupotte/followers","following_url":"https://api.github.com/users/poupotte/following{/other_user}","gists_url":"https://api.github.com/users/poupotte/gists{/gist_id}","starred_url":"https://api.github.com/users/poupotte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poupotte/subscriptions","organizations_url":"https://api.github.com/users/poupotte/orgs","repos_url":"https://api.github.com/users/poupotte/repos","events_url":"https://api.github.com/users/poupotte/events{/privacy}","received_events_url":"https://api.github.com/users/poupotte/received_events","type":"User","site_admin":false},"body":"Refs #121","created_at":"2015-02-26T08:31:03Z","updated_at":"2015-03-03T14:50:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3120a7d40051beddb3b75da88ee4804b084863da","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125/commits","review_comments_url":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125/comments","review_comment_url":"https://api.github.com/repos/cozy/cozy-data-system/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cozy/cozy-data-system/issues/125/comments","statuses_url":"https://api.github.com/repos/cozy/cozy-data-system/statuses/e450c8c05ceed59473a722b45bfd0849422c550e","head":{"label":"poupotte:master","ref":"master","sha":"e450c8c05ceed59473a722b45bfd0849422c550e","user":{"login":"poupotte","id":2659119,"avatar_url":"https://avatars.githubusercontent.com/u/2659119?v=3","gravatar_id":"","url":"https://api.github.com/users/poupotte","html_url":"https://github.com/poupotte","followers_url":"https://api.github.com/users/poupotte/followers","following_url":"https://api.github.com/users/poupotte/following{/other_user}","gists_url":"https://api.github.com/users/poupotte/gists{/gist_id}","starred_url":"https://api.github.com/users/poupotte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poupotte/subscriptions","organizations_url":"https://api.github.com/users/poupotte/orgs","repos_url":"https://api.github.com/users/poupotte/repos","events_url":"https://api.github.com/users/poupotte/events{/privacy}","received_events_url":"https://api.github.com/users/poupotte/received_events","type":"User","site_admin":false},"repo":{"id":9026525,"name":"cozy-data-system","full_name":"poupotte/cozy-data-system","owner":{"login":"poupotte","id":2659119,"avatar_url":"https://avatars.githubusercontent.com/u/2659119?v=3","gravatar_id":"","url":"https://api.github.com/users/poupotte","html_url":"https://github.com/poupotte","followers_url":"https://api.github.com/users/poupotte/followers","following_url":"https://api.github.com/users/poupotte/following{/other_user}","gists_url":"https://api.github.com/users/poupotte/gists{/gist_id}","starred_url":"https://api.github.com/users/poupotte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/poupotte/subscriptions","organizations_url":"https://api.github.com/users/poupotte/orgs","repos_url":"https://api.github.com/users/poupotte/repos","events_url":"https://api.github.com/users/poupotte/events{/privacy}","received_events_url":"https://api.github.com/users/poupotte/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/poupotte/cozy-data-system","description":"Data Layer for Cozy Cloud platform","fork":true,"url":"https://api.github.com/repos/poupotte/cozy-data-system","forks_url":"https://api.github.com/repos/poupotte/cozy-data-system/forks","keys_url":"https://api.github.com/repos/poupotte/cozy-data-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/poupotte/cozy-data-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/poupotte/cozy-data-system/teams","hooks_url":"https://api.github.com/repos/poupotte/cozy-data-system/hooks","issue_events_url":"https://api.github.com/repos/poupotte/cozy-data-system/issues/events{/number}","events_url":"https://api.github.com/repos/poupotte/cozy-data-system/events","assignees_url":"https://api.github.com/repos/poupotte/cozy-data-system/assignees{/user}","branches_url":"https://api.github.com/repos/poupotte/cozy-data-system/branches{/branch}","tags_url":"https://api.github.com/repos/poupotte/cozy-data-system/tags","blobs_url":"https://api.github.com/repos/poupotte/cozy-data-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/poupotte/cozy-data-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/poupotte/cozy-data-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/poupotte/cozy-data-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/poupotte/cozy-data-system/statuses/{sha}","languages_url":"https://api.github.com/repos/poupotte/cozy-data-system/languages","stargazers_url":"https://api.github.com/repos/poupotte/cozy-data-system/stargazers","contributors_url":"https://api.github.com/repos/poupotte/cozy-data-system/contributors","subscribers_url":"https://api.github.com/repos/poupotte/cozy-data-system/subscribers","subscription_url":"https://api.github.com/repos/poupotte/cozy-data-system/subscription","commits_url":"https://api.github.com/repos/poupotte/cozy-data-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/poupotte/cozy-data-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/poupotte/cozy-data-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/poupotte/cozy-data-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/poupotte/cozy-data-system/contents/{+path}","compare_url":"https://api.github.com/repos/poupotte/cozy-data-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/poupotte/cozy-data-system/merges","archive_url":"https://api.github.com/repos/poupotte/cozy-data-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/poupotte/cozy-data-system/downloads","issues_url":"https://api.github.com/repos/poupotte/cozy-data-system/issues{/number}","pulls_url":"https://api.github.com/repos/poupotte/cozy-data-system/pulls{/number}","milestones_url":"https://api.github.com/repos/poupotte/cozy-data-system/milestones{/number}","notifications_url":"https://api.github.com/repos/poupotte/cozy-data-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/poupotte/cozy-data-system/labels{/name}","releases_url":"https://api.github.com/repos/poupotte/cozy-data-system/releases{/id}","created_at":"2013-03-26T09:03:56Z","updated_at":"2015-03-03T10:29:47Z","pushed_at":"2015-03-03T10:29:47Z","git_url":"git://github.com/poupotte/cozy-data-system.git","ssh_url":"git@github.com:poupotte/cozy-data-system.git","clone_url":"https://github.com/poupotte/cozy-data-system.git","svn_url":"https://github.com/poupotte/cozy-data-system","homepage":"cozycloud.cc","size":2213,"stargazers_count":0,"watchers_count":0,"language":"CoffeeScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cozy:master","ref":"master","sha":"06988c33e28e04e97595e5c65d1909ab7ab44704","user":{"login":"cozy","id":7690525,"avatar_url":"https://avatars.githubusercontent.com/u/7690525?v=3","gravatar_id":"","url":"https://api.github.com/users/cozy","html_url":"https://github.com/cozy","followers_url":"https://api.github.com/users/cozy/followers","following_url":"https://api.github.com/users/cozy/following{/other_user}","gists_url":"https://api.github.com/users/cozy/gists{/gist_id}","starred_url":"https://api.github.com/users/cozy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cozy/subscriptions","organizations_url":"https://api.github.com/users/cozy/orgs","repos_url":"https://api.github.com/users/cozy/repos","events_url":"https://api.github.com/users/cozy/events{/privacy}","received_events_url":"https://api.github.com/users/cozy/received_events","type":"Organization","site_admin":false},"repo":{"id":5093292,"name":"cozy-data-system","full_name":"cozy/cozy-data-system","owner":{"login":"cozy","id":7690525,"avatar_url":"https://avatars.githubusercontent.com/u/7690525?v=3","gravatar_id":"","url":"https://api.github.com/users/cozy","html_url":"https://github.com/cozy","followers_url":"https://api.github.com/users/cozy/followers","following_url":"https://api.github.com/users/cozy/following{/other_user}","gists_url":"https://api.github.com/users/cozy/gists{/gist_id}","starred_url":"https://api.github.com/users/cozy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cozy/subscriptions","organizations_url":"https://api.github.com/users/cozy/orgs","repos_url":"https://api.github.com/users/cozy/repos","events_url":"https://api.github.com/users/cozy/events{/privacy}","received_events_url":"https://api.github.com/users/cozy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cozy/cozy-data-system","description":"Data Layer for Cozy Platform","fork":false,"url":"https://api.github.com/repos/cozy/cozy-data-system","forks_url":"https://api.github.com/repos/cozy/cozy-data-system/forks","keys_url":"https://api.github.com/repos/cozy/cozy-data-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cozy/cozy-data-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cozy/cozy-data-system/teams","hooks_url":"https://api.github.com/repos/cozy/cozy-data-system/hooks","issue_events_url":"https://api.github.com/repos/cozy/cozy-data-system/issues/events{/number}","events_url":"https://api.github.com/repos/cozy/cozy-data-system/events","assignees_url":"https://api.github.com/repos/cozy/cozy-data-system/assignees{/user}","branches_url":"https://api.github.com/repos/cozy/cozy-data-system/branches{/branch}","tags_url":"https://api.github.com/repos/cozy/cozy-data-system/tags","blobs_url":"https://api.github.com/repos/cozy/cozy-data-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cozy/cozy-data-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cozy/cozy-data-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/cozy/cozy-data-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cozy/cozy-data-system/statuses/{sha}","languages_url":"https://api.github.com/repos/cozy/cozy-data-system/languages","stargazers_url":"https://api.github.com/repos/cozy/cozy-data-system/stargazers","contributors_url":"https://api.github.com/repos/cozy/cozy-data-system/contributors","subscribers_url":"https://api.github.com/repos/cozy/cozy-data-system/subscribers","subscription_url":"https://api.github.com/repos/cozy/cozy-data-system/subscription","commits_url":"https://api.github.com/repos/cozy/cozy-data-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/cozy/cozy-data-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/cozy/cozy-data-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/cozy/cozy-data-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/cozy/cozy-data-system/contents/{+path}","compare_url":"https://api.github.com/repos/cozy/cozy-data-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cozy/cozy-data-system/merges","archive_url":"https://api.github.com/repos/cozy/cozy-data-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cozy/cozy-data-system/downloads","issues_url":"https://api.github.com/repos/cozy/cozy-data-system/issues{/number}","pulls_url":"https://api.github.com/repos/cozy/cozy-data-system/pulls{/number}","milestones_url":"https://api.github.com/repos/cozy/cozy-data-system/milestones{/number}","notifications_url":"https://api.github.com/repos/cozy/cozy-data-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cozy/cozy-data-system/labels{/name}","releases_url":"https://api.github.com/repos/cozy/cozy-data-system/releases{/id}","created_at":"2012-07-18T07:58:49Z","updated_at":"2015-02-20T10:04:49Z","pushed_at":"2015-02-20T10:04:48Z","git_url":"git://github.com/cozy/cozy-data-system.git","ssh_url":"git@github.com:cozy/cozy-data-system.git","clone_url":"https://github.com/cozy/cozy-data-system.git","svn_url":"https://github.com/cozy/cozy-data-system","homepage":"cozy.io","size":2651,"stargazers_count":17,"watchers_count":17,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":7,"forks":8,"open_issues":7,"watchers":17,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125"},"html":{"href":"https://github.com/cozy/cozy-data-system/pull/125"},"issue":{"href":"https://api.github.com/repos/cozy/cozy-data-system/issues/125"},"comments":{"href":"https://api.github.com/repos/cozy/cozy-data-system/issues/125/comments"},"review_comments":{"href":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125/comments"},"review_comment":{"href":"https://api.github.com/repos/cozy/cozy-data-system/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cozy/cozy-data-system/pulls/125/commits"},"statuses":{"href":"https://api.github.com/repos/cozy/cozy-data-system/statuses/e450c8c05ceed59473a722b45bfd0849422c550e"}}}}