Last active
August 12, 2016 02:36
-
-
Save inlightmedia/7a403b31c3d891265882077b2f1eac1e to your computer and use it in GitHub Desktop.
Parse Roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
<script src="http://www.parsecdn.com/js/parse-latest.js"></script> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
/********************************************** | |
1) Login with the username and password you created in the previous section. | |
2) Make the blog post created in function createBlogPostWithACL readable | |
by everyone but only writable by you. | |
HINT: Use an ACL | |
3) Flesh out the ensureRoles function, create a role called "Admin" and | |
make sure the currently logged in user has write access and is a member. | |
4) Make the blog post created in function createBlogPostWithRole readable | |
by everyone but only writable by all Admins. | |
HINT: Use the role you created in the ensureRoles function | |
***********************************************/ | |
Parse.initialize("<YOUR APP ID>"); | |
Parse.serverURL = '<YOUR SERVER URL>'; | |
function ensureRoles() { | |
var promise = new Parse.Promise(); | |
// Create the role, save it and add youself as the user, remember | |
// to call promise.resolve() at the end :) | |
var roleACL = new Parse.ACL(); | |
roleACL.setPublicReadAccess(true); | |
roleACL.setWriteAccess(Parse.User.current(), true); | |
var role = new Parse.Role("Admin", roleACL); | |
role.save().then(function () { | |
// Add the current user to the list of Admin users. | |
role.getUsers().add(Parse.User.current()); | |
// Save the role list now that current user has been added. | |
role.save().then(function () { | |
console.log("Role created " + role.id); | |
promise.resolve(); | |
}); | |
}); | |
// promise.resolve(); | |
return promise; | |
} | |
function createBlogPostWithACL() { | |
var promise = new Parse.Promise(); | |
var BlogPost = Parse.Object.extend("BlogPost"); | |
var post = new BlogPost(); | |
post.set("cotent", "This is some content"); | |
post.set("published", true); | |
var postACL = new Parse.ACL(); | |
postACL.setWriteAccess(Parse.User.current(), true); | |
postACL.setPublicReadAccess(true) | |
post.setACL(postACL); | |
post.save().then(function() { | |
console.log("Saved normal blog post with ACL " + post.id); | |
promise.resolve(); | |
}); | |
return promise; | |
} | |
function createBlogPostWithRole() { | |
var promise = new Parse.Promise(); | |
var BlogPost = Parse.Object.extend("BlogPost"); | |
var post = new BlogPost(); | |
post.set("cotent", "This is some content"); | |
post.set("published", true); | |
var roleACL = new Parse.ACL(); | |
roleACL.setRoleWriteAccess("Admin", true); | |
roleACL.setPublicReadAccess(true) | |
post.setACL(roleACL); | |
post.save().then(function() { | |
console.log("Saved role blog post with ACL " + post.id); | |
promise.resolve(); | |
}); | |
return promise; | |
} | |
Parse.User.logIn("[email protected]", "pass001") | |
.then(createBlogPostWithACL) | |
.then(ensureRoles) | |
.then(createBlogPostWithRole); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">/********************************************** | |
1) Login with the username and password you created in the previous section. | |
2) Make the blog post created in function createBlogPostWithACL readable | |
by everyone but only writable by you. | |
HINT: Use an ACL | |
3) Flesh out the ensureRoles function, create a role called "Admin" and | |
make sure the currently logged in user has write access and is a member. | |
4) Make the blog post created in function createBlogPostWithRole readable | |
by everyone but only writable by all Admins. | |
HINT: Use the role you created in the ensureRoles function | |
***********************************************/ | |
Parse.initialize("<YOUR APP ID>"); | |
Parse.serverURL = '<YOUR SERVER URL>'; | |
function ensureRoles() { | |
var promise = new Parse.Promise(); | |
// Create the role, save it and add youself as the user, remember | |
// to call promise.resolve() at the end :) | |
var roleACL = new Parse.ACL(); | |
roleACL.setPublicReadAccess(true); | |
roleACL.setWriteAccess(Parse.User.current(), true); | |
var role = new Parse.Role("Admin", roleACL); | |
role.save().then(function () { | |
// Add the current user to the list of Admin users. | |
role.getUsers().add(Parse.User.current()); | |
// Save the role list now that current user has been added. | |
role.save().then(function () { | |
console.log("Role created " + role.id); | |
promise.resolve(); | |
}); | |
}); | |
// promise.resolve(); | |
return promise; | |
} | |
function createBlogPostWithACL() { | |
var promise = new Parse.Promise(); | |
var BlogPost = Parse.Object.extend("BlogPost"); | |
var post = new BlogPost(); | |
post.set("cotent", "This is some content"); | |
post.set("published", true); | |
var postACL = new Parse.ACL(); | |
postACL.setWriteAccess(Parse.User.current(), true); | |
postACL.setPublicReadAccess(true) | |
post.setACL(postACL); | |
post.save().then(function() { | |
console.log("Saved normal blog post with ACL " + post.id); | |
promise.resolve(); | |
}); | |
return promise; | |
} | |
function createBlogPostWithRole() { | |
var promise = new Parse.Promise(); | |
var BlogPost = Parse.Object.extend("BlogPost"); | |
var post = new BlogPost(); | |
post.set("cotent", "This is some content"); | |
post.set("published", true); | |
var roleACL = new Parse.ACL(); | |
roleACL.setRoleWriteAccess("Admin", true); | |
roleACL.setPublicReadAccess(true) | |
post.setACL(roleACL); | |
post.save().then(function() { | |
console.log("Saved role blog post with ACL " + post.id); | |
promise.resolve(); | |
}); | |
return promise; | |
} | |
Parse.User.logIn("[email protected]", "pass001") | |
.then(createBlogPostWithACL) | |
.then(ensureRoles) | |
.then(createBlogPostWithRole); | |
</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************** | |
1) Login with the username and password you created in the previous section. | |
2) Make the blog post created in function createBlogPostWithACL readable | |
by everyone but only writable by you. | |
HINT: Use an ACL | |
3) Flesh out the ensureRoles function, create a role called "Admin" and | |
make sure the currently logged in user has write access and is a member. | |
4) Make the blog post created in function createBlogPostWithRole readable | |
by everyone but only writable by all Admins. | |
HINT: Use the role you created in the ensureRoles function | |
***********************************************/ | |
Parse.initialize("yourAppId"); | |
Parse.serverURL = 'https://inlightmedia-parse-server.herokuapp.com/parse'; | |
function ensureRoles() { | |
var promise = new Parse.Promise(); | |
// Create the role, save it and add youself as the user, remember | |
// to call promise.resolve() at the end :) | |
var roleACL = new Parse.ACL(); | |
roleACL.setPublicReadAccess(true); | |
roleACL.setWriteAccess(Parse.User.current(), true); | |
var role = new Parse.Role("Admin", roleACL); | |
role.save().then(function () { | |
// Add the current user to the list of Admin users. | |
role.getUsers().add(Parse.User.current()); | |
// Save the role list now that current user has been added. | |
role.save().then(function () { | |
console.log("Role created " + role.id); | |
promise.resolve(); | |
}); | |
}); | |
// promise.resolve(); | |
return promise; | |
} | |
function createBlogPostWithACL() { | |
var promise = new Parse.Promise(); | |
var BlogPost = Parse.Object.extend("BlogPost"); | |
var post = new BlogPost(); | |
post.set("cotent", "This is some content"); | |
post.set("published", true); | |
var postACL = new Parse.ACL(); | |
postACL.setWriteAccess(Parse.User.current(), true); | |
postACL.setPublicReadAccess(true) | |
post.setACL(postACL); | |
post.save().then(function() { | |
console.log("Saved normal blog post with ACL " + post.id); | |
promise.resolve(); | |
}); | |
return promise; | |
} | |
function createBlogPostWithRole() { | |
var promise = new Parse.Promise(); | |
var BlogPost = Parse.Object.extend("BlogPost"); | |
var post = new BlogPost(); | |
post.set("cotent", "This is some content"); | |
post.set("published", true); | |
var roleACL = new Parse.ACL(); | |
roleACL.setRoleWriteAccess("Admin", true); | |
roleACL.setPublicReadAccess(true) | |
post.setACL(roleACL); | |
post.save().then(function() { | |
console.log("Saved role blog post with ACL " + post.id); | |
promise.resolve(); | |
}); | |
return promise; | |
} | |
Parse.User.logIn("[email protected]", "pass001") | |
.then(createBlogPostWithACL) | |
.then(ensureRoles) | |
.then(createBlogPostWithRole); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment