{"action":"created","comment":{"url":"https://api.github.com/repos/leancloud/docs/pulls/comments/39364335","id":39364335,"diff_hunk":"@@ -0,0 +1,219 @@\n+{% extends \"./acl_guide.tmpl\" %}\n+\n+{% block create_post_set_acl_for_single_user %}\n+\n+```objc\n+    // 新建一个帖子对象\n+    AVObject *post = [AVObject objectWithClassName:@\"Post\"];\n+    [post setObject:@\"大家好，我是新人\" forKey:@\"title\"];\n+    \n+    //新建一个 ACL 实例\n+    AVACL *acl = [AVACL ACL];\n+    [acl setPublicReadAccess:YES];// 设置公开的「读」权限，任何人都可阅读\n+    [acl setWriteAccess:YES forUser:[AVUser currentUser]];// 为当前用户赋予「写」权限，有且仅有当前用户可以修改这条 Post\n+    post.ACL = acl;// 将 ACL 实例赋予 Post对象\n+    \n+    [post saveInBackground];\n+```\n+\n+{% endblock %}\n+\n+{% block create_post_set_acl_for_othter_user %}\n+\n+```objc\n+    AVQuery *query = [AVUser query];\n+    [query whereKey:@\"objectId\" equalTo:@\"55f1572460b2ce30e8b7afde\"];\n+    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+        if (error == nil) {\n+            // 新建一个帖子对象\n+            AVObject *post = [AVObject objectWithClassName:@\"Post\"];\n+            [post setObject:@\"这是我的第二条发言，谢谢大家！\" forKey:@\"title\"];\n+            [post setObject:@\"我最近喜欢看足球和篮球了。\" forKey:@\"content\"];\n+            \n+            //新建一个 ACL 实例\n+            AVACL *acl = [AVACL ACL];\n+            [acl setPublicReadAccess:YES];// 设置公开的「读」权限，任何人都可阅读\n+            [acl setWriteAccess:YES forUser:[AVUser currentUser]];// 为当前用户赋予「写」权限\n+            \n+            AVUser *othterUser = [objects objectAtIndex:0];// 读取 admin\n+            [acl setWriteAccess:YES forUser:othterUser];\n+            \n+            post.ACL = acl;// 将 ACL 实例赋予 Post 对象\n+            \n+            [post saveInBackground];\n+            \n+        } else {\n+            NSLog(@\"error\");\n+        }\n+    }];\n+```\n+{% endblock %}\n+\n+{% block create_role_administrator %}\n+\n+```\n+    // 新建一个角色，并把为当前用户赋予该角色\n+    AVRole *administrator =[AVRole roleWithName:@\"Administrator\"];//新建角色\n+    [[administrator users] addObject: [AVUser currentUser]];//为当前用户赋予该角色\n+    [administrator saveInBackground];//保存\n+```\n+{% endblock %}\n+\n+{% block query_role_administrator %}\n+\n+```\n+    // 构建角色的查询，并且查看该角色所对应的用户\n+    AVQuery *roleQuery= [AVRole query];\n+    [roleQuery whereKey:@\"name\" equalTo:@\"Administrator\"];\n+    [roleQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+        AVRole *administrator=[objects objectAtIndex:0];\n+        AVRelation *userRelation =[administrator users];\n+        AVQuery *userQuery= [userRelation query];\n+        [userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+            // objects 就是拥有该角色权限的所有用户了。\n+        }];\n+    }];\n+```\n+{% endblock %}\n+\n+{% block query_role_of_user %}\n+\n+```\n+    AVQuery *roleQuery= [AVRole query];\n+    [roleQuery whereKey:@\"users\" equalTo: [AVUser currentUser]];\n+    [roleQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+        // objects 就是一个 AVRole 的数组，这些 AVRole 就是当前用户所在拥有的角色\n+    }];\n+```\n+{% endblock %}\n+\n+{% block query_user_of_role %}\n+\n+```\n+    AVRole *moderatorRole=//根据 id 查询或者根据 name 查询出一个实例\n+    AVRelation *userRelation =[moderatorRole users];\n+    AVQuery *userQuery= [userRelation query];\n+    [userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+        // objects 就是拥有 moderatorRole 角色的所有用户了。\n+    }];\n+```\n+{% endblock %}\n+\n+{% block add_role_for_user %}\n+\n+```\n+    AVQuery *roleQuery= [AVRole query];\n+    [roleQuery whereKey:@\"name\" equalTo:@\"Moderator\"];\n+    [roleQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+        // 如果角色存在\n+        if ([objects count] > 0) {\n+            AVRole *moderatorRole= [objects objectAtIndex:0];\n+            [roleQuery whereKey:@\"users\" equalTo:[AVUser currentUser]];\n+            [roleQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){\n+                if ([objects count] == 0) {\n+                    //为用户赋予角色\n+                    [[moderatorRole users ] addObject:[AVUser currentUser]];\n+                    [moderatorRole saveInBackground];\n+                } else {\n+                    NSLog(@\"已经拥有 Moderator 角色了。\");\n+                }\n+            }];\n+            \n+        } else {\n+            // 角色不存在，就新建角色\n+            AVRole *moderatorRole =[AVRole roleWithName:@\"Moderator\"];\n+            [[moderatorRole users ] addObject:[AVUser currentUser]];// 赋予角色\n+            [moderatorRole saveInBackground];\n+        }\n+    }];\n+```\n+{% endblock %}\n+\n+{% block remove_role_from_user %}\n+\n+```\n+    AVQuery *roleQuery= [AVRole query];\n+    [roleQuery whereKey:@\"name\" equalTo:@\"Moderator\"];\n+    [roleQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {\n+        // 如果角色存在\n+        if ([objects count] > 0) {\n+            AVRole *moderatorRole= [objects objectAtIndex:0];\n+            [roleQuery whereKey:@\"users\" equalTo:[AVUser currentUser]];\n+            [roleQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){\n+                // 如果用户确实拥有该角色，那么就剥夺\n+                if ([objects count] > 0) {\n+                    [[moderatorRole users ]  removeObject:[AVUser currentUser]];\n+                    [moderatorRole saveInBackground];\n+                }\n+            }];\n+        }\n+    }];\n+```\n+{% endblock %}\n+\n+{% block asign_role_to_parent %}\n+\n+```\n+    AVRole *administratorRole = [AVRole roleWithName:@\"Administrator\"];\n+    AVRole *moderator = [AVRole roleWithName:@\"Moderator\"];\n+    \n+    [administratorRole save];\n+    [administratorRole save];","path":"views/acl_guide-ios.md","position":161,"original_position":161,"commit_id":"93ce243861d00c6cef1ab1ed5b1de1e5c638a544","original_commit_id":"93ce243861d00c6cef1ab1ed5b1de1e5c638a544","user":{"login":"sdjcw","id":1127984,"avatar_url":"https://avatars.githubusercontent.com/u/1127984?v=3","gravatar_id":"","url":"https://api.github.com/users/sdjcw","html_url":"https://github.com/sdjcw","followers_url":"https://api.github.com/users/sdjcw/followers","following_url":"https://api.github.com/users/sdjcw/following{/other_user}","gists_url":"https://api.github.com/users/sdjcw/gists{/gist_id}","starred_url":"https://api.github.com/users/sdjcw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sdjcw/subscriptions","organizations_url":"https://api.github.com/users/sdjcw/orgs","repos_url":"https://api.github.com/users/sdjcw/repos","events_url":"https://api.github.com/users/sdjcw/events{/privacy}","received_events_url":"https://api.github.com/users/sdjcw/received_events","type":"User","site_admin":false},"body":"这里代码好像有问题。","created_at":"2015-09-14T06:39:03Z","updated_at":"2015-09-14T06:39:03Z","html_url":"https://github.com/leancloud/docs/pull/522#discussion_r39364335","pull_request_url":"https://api.github.com/repos/leancloud/docs/pulls/522","_links":{"self":{"href":"https://api.github.com/repos/leancloud/docs/pulls/comments/39364335"},"html":{"href":"https://github.com/leancloud/docs/pull/522#discussion_r39364335"},"pull_request":{"href":"https://api.github.com/repos/leancloud/docs/pulls/522"}}},"pull_request":{"url":"https://api.github.com/repos/leancloud/docs/pulls/522","id":44644745,"html_url":"https://github.com/leancloud/docs/pull/522","diff_url":"https://github.com/leancloud/docs/pull/522.diff","patch_url":"https://github.com/leancloud/docs/pull/522.patch","issue_url":"https://api.github.com/repos/leancloud/docs/issues/522","number":522,"state":"open","locked":false,"title":"添加一个全新的 ACL 快速指南文档。","user":{"login":"wujun4code","id":5119542,"avatar_url":"https://avatars.githubusercontent.com/u/5119542?v=3","gravatar_id":"","url":"https://api.github.com/users/wujun4code","html_url":"https://github.com/wujun4code","followers_url":"https://api.github.com/users/wujun4code/followers","following_url":"https://api.github.com/users/wujun4code/following{/other_user}","gists_url":"https://api.github.com/users/wujun4code/gists{/gist_id}","starred_url":"https://api.github.com/users/wujun4code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wujun4code/subscriptions","organizations_url":"https://api.github.com/users/wujun4code/orgs","repos_url":"https://api.github.com/users/wujun4code/repos","events_url":"https://api.github.com/users/wujun4code/events{/privacy}","received_events_url":"https://api.github.com/users/wujun4code/received_events","type":"User","site_admin":false},"body":"全新添加一个 ACL 的快速指南文档，ACL 开发指南还在编写中，请先review 快速指南，我写这个指南的初衷就是想在最短的篇幅内，告诉开发者设置 ACL 和不设置 ACL 的区别在哪里，关于  ACL 的具体用法会有一个新的文档（正在编写中）做全面开发指导。\r\n\r\n@jwfing @sdjcw @killme2008 ","created_at":"2015-09-10T09:20:45Z","updated_at":"2015-09-14T06:39:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"feb49dbb7521c0e233a5f1161d04d9484e5ac73d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/leancloud/docs/pulls/522/commits","review_comments_url":"https://api.github.com/repos/leancloud/docs/pulls/522/comments","review_comment_url":"https://api.github.com/repos/leancloud/docs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/leancloud/docs/issues/522/comments","statuses_url":"https://api.github.com/repos/leancloud/docs/statuses/93ce243861d00c6cef1ab1ed5b1de1e5c638a544","head":{"label":"wujun4code:add_acl_quick_start_doc","ref":"add_acl_quick_start_doc","sha":"93ce243861d00c6cef1ab1ed5b1de1e5c638a544","user":{"login":"wujun4code","id":5119542,"avatar_url":"https://avatars.githubusercontent.com/u/5119542?v=3","gravatar_id":"","url":"https://api.github.com/users/wujun4code","html_url":"https://github.com/wujun4code","followers_url":"https://api.github.com/users/wujun4code/followers","following_url":"https://api.github.com/users/wujun4code/following{/other_user}","gists_url":"https://api.github.com/users/wujun4code/gists{/gist_id}","starred_url":"https://api.github.com/users/wujun4code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wujun4code/subscriptions","organizations_url":"https://api.github.com/users/wujun4code/orgs","repos_url":"https://api.github.com/users/wujun4code/repos","events_url":"https://api.github.com/users/wujun4code/events{/privacy}","received_events_url":"https://api.github.com/users/wujun4code/received_events","type":"User","site_admin":false},"repo":{"id":29326977,"name":"docs","full_name":"wujun4code/docs","owner":{"login":"wujun4code","id":5119542,"avatar_url":"https://avatars.githubusercontent.com/u/5119542?v=3","gravatar_id":"","url":"https://api.github.com/users/wujun4code","html_url":"https://github.com/wujun4code","followers_url":"https://api.github.com/users/wujun4code/followers","following_url":"https://api.github.com/users/wujun4code/following{/other_user}","gists_url":"https://api.github.com/users/wujun4code/gists{/gist_id}","starred_url":"https://api.github.com/users/wujun4code/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wujun4code/subscriptions","organizations_url":"https://api.github.com/users/wujun4code/orgs","repos_url":"https://api.github.com/users/wujun4code/repos","events_url":"https://api.github.com/users/wujun4code/events{/privacy}","received_events_url":"https://api.github.com/users/wujun4code/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wujun4code/docs","description":"LeanCloud Documentation","fork":true,"url":"https://api.github.com/repos/wujun4code/docs","forks_url":"https://api.github.com/repos/wujun4code/docs/forks","keys_url":"https://api.github.com/repos/wujun4code/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wujun4code/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wujun4code/docs/teams","hooks_url":"https://api.github.com/repos/wujun4code/docs/hooks","issue_events_url":"https://api.github.com/repos/wujun4code/docs/issues/events{/number}","events_url":"https://api.github.com/repos/wujun4code/docs/events","assignees_url":"https://api.github.com/repos/wujun4code/docs/assignees{/user}","branches_url":"https://api.github.com/repos/wujun4code/docs/branches{/branch}","tags_url":"https://api.github.com/repos/wujun4code/docs/tags","blobs_url":"https://api.github.com/repos/wujun4code/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wujun4code/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wujun4code/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/wujun4code/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wujun4code/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/wujun4code/docs/languages","stargazers_url":"https://api.github.com/repos/wujun4code/docs/stargazers","contributors_url":"https://api.github.com/repos/wujun4code/docs/contributors","subscribers_url":"https://api.github.com/repos/wujun4code/docs/subscribers","subscription_url":"https://api.github.com/repos/wujun4code/docs/subscription","commits_url":"https://api.github.com/repos/wujun4code/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/wujun4code/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/wujun4code/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/wujun4code/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/wujun4code/docs/contents/{+path}","compare_url":"https://api.github.com/repos/wujun4code/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wujun4code/docs/merges","archive_url":"https://api.github.com/repos/wujun4code/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wujun4code/docs/downloads","issues_url":"https://api.github.com/repos/wujun4code/docs/issues{/number}","pulls_url":"https://api.github.com/repos/wujun4code/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/wujun4code/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/wujun4code/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wujun4code/docs/labels{/name}","releases_url":"https://api.github.com/repos/wujun4code/docs/releases{/id}","created_at":"2015-01-16T01:31:32Z","updated_at":"2015-01-06T06:57:48Z","pushed_at":"2015-09-14T03:20:31Z","git_url":"git://github.com/wujun4code/docs.git","ssh_url":"git@github.com:wujun4code/docs.git","clone_url":"https://github.com/wujun4code/docs.git","svn_url":"https://github.com/wujun4code/docs","homepage":"http://leancloud.cn/docs/","size":24093,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"leancloud:master","ref":"master","sha":"21aa6f0099baf6e86b0c4ec1ae0c2ff5fb0cd0fd","user":{"login":"leancloud","id":6660518,"avatar_url":"https://avatars.githubusercontent.com/u/6660518?v=3","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"repo":{"id":25067518,"name":"docs","full_name":"leancloud/docs","owner":{"login":"leancloud","id":6660518,"avatar_url":"https://avatars.githubusercontent.com/u/6660518?v=3","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/leancloud/docs","description":"LeanCloud Documentation","fork":false,"url":"https://api.github.com/repos/leancloud/docs","forks_url":"https://api.github.com/repos/leancloud/docs/forks","keys_url":"https://api.github.com/repos/leancloud/docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leancloud/docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leancloud/docs/teams","hooks_url":"https://api.github.com/repos/leancloud/docs/hooks","issue_events_url":"https://api.github.com/repos/leancloud/docs/issues/events{/number}","events_url":"https://api.github.com/repos/leancloud/docs/events","assignees_url":"https://api.github.com/repos/leancloud/docs/assignees{/user}","branches_url":"https://api.github.com/repos/leancloud/docs/branches{/branch}","tags_url":"https://api.github.com/repos/leancloud/docs/tags","blobs_url":"https://api.github.com/repos/leancloud/docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leancloud/docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leancloud/docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/leancloud/docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leancloud/docs/statuses/{sha}","languages_url":"https://api.github.com/repos/leancloud/docs/languages","stargazers_url":"https://api.github.com/repos/leancloud/docs/stargazers","contributors_url":"https://api.github.com/repos/leancloud/docs/contributors","subscribers_url":"https://api.github.com/repos/leancloud/docs/subscribers","subscription_url":"https://api.github.com/repos/leancloud/docs/subscription","commits_url":"https://api.github.com/repos/leancloud/docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/leancloud/docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/leancloud/docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/leancloud/docs/issues/comments{/number}","contents_url":"https://api.github.com/repos/leancloud/docs/contents/{+path}","compare_url":"https://api.github.com/repos/leancloud/docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leancloud/docs/merges","archive_url":"https://api.github.com/repos/leancloud/docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leancloud/docs/downloads","issues_url":"https://api.github.com/repos/leancloud/docs/issues{/number}","pulls_url":"https://api.github.com/repos/leancloud/docs/pulls{/number}","milestones_url":"https://api.github.com/repos/leancloud/docs/milestones{/number}","notifications_url":"https://api.github.com/repos/leancloud/docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leancloud/docs/labels{/name}","releases_url":"https://api.github.com/repos/leancloud/docs/releases{/id}","created_at":"2014-10-11T07:14:37Z","updated_at":"2015-09-14T05:23:00Z","pushed_at":"2015-09-14T06:11:49Z","git_url":"git://github.com/leancloud/docs.git","ssh_url":"git@github.com:leancloud/docs.git","clone_url":"https://github.com/leancloud/docs.git","svn_url":"https://github.com/leancloud/docs","homepage":"http://leancloud.cn/docs/","size":28615,"stargazers_count":135,"watchers_count":135,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":103,"mirror_url":null,"open_issues_count":50,"forks":103,"open_issues":50,"watchers":135,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/leancloud/docs/pulls/522"},"html":{"href":"https://github.com/leancloud/docs/pull/522"},"issue":{"href":"https://api.github.com/repos/leancloud/docs/issues/522"},"comments":{"href":"https://api.github.com/repos/leancloud/docs/issues/522/comments"},"review_comments":{"href":"https://api.github.com/repos/leancloud/docs/pulls/522/comments"},"review_comment":{"href":"https://api.github.com/repos/leancloud/docs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/leancloud/docs/pulls/522/commits"},"statuses":{"href":"https://api.github.com/repos/leancloud/docs/statuses/93ce243861d00c6cef1ab1ed5b1de1e5c638a544"}}}}