Skip to content

Instantly share code, notes, and snippets.

@joahg
Created November 26, 2013 17:27
Show Gist options
  • Save joahg/7662431 to your computer and use it in GitHub Desktop.
Save joahg/7662431 to your computer and use it in GitHub Desktop.
Eases promotion/demotion of Codecademy Groups Co-Leaders.
(function () {
if (!(typeof CCDATA.page != "undefined" && typeof CCDATA.page.group != "undefined")) {
alert("You are not viewing a valid CC Group Page.");
return false
}
if (CCDATA.current_user._id !== CCDATA.page.group.roles.leader[0]) {
alert("You do not have permission to demote a user in this group.");
return false
}
var e = prompt("Enter the username or ID of the user you would like to demote from moderator to normal user. You can retrieve a user's ID by running 'CCDATA.page.user._id' in your javascript console on their profile page. \n \n Sometimes usernames will not work correctly and you must use the ID of the user.");
var t = function () {
p = $.parseJSON(x.responseText);
$.ajax({
url: "http://www.codecademy.com/groups/" + CCDATA.page.group._id + "/users/role",
dataType: "json",
type: "DELETE",
data: {
user_id: e,
role: "moderator"
},
beforeSend: function (e) {
e.setRequestHeader("X-CSRF-Token", csrf_token);
e.setRequestHeader("X-Requested-With", "XMLHttpRequest");
e.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.0")
},
error: function (e, t, n) {
console.log(e.responseText);
console.log(n)
}
})
};
x = new XMLHttpRequest;
x.onload = t;
x.open("GET", "http://www.codecademy.com/api/v1/users/" + e, true);
x.setRequestHeader("X-CSRF-Token", csrf_token);
x.send(null)
})()
(function () {
if (!(typeof CCDATA.page != "undefined" && typeof CCDATA.page.group != "undefined")) {
alert("You are not viewing a valid CC Group Page.");
return false
}
var e = prompt("Enter the username or ID of the user you would like to promote. You can retrieve a user's ID by running 'CCDATA.page.user._id' in your javascript console on their profile page. \n \n Sometimes usernames will not work correctly and you must use the ID of the user.");
var t = function () {
p = $.parseJSON(x.responseText);
$.ajax({
url: "http://www.codecademy.com/groups/" + CCDATA.page.group._id + "/users/role",
dataType: "json",
type: "POST",
data: {
user_id: p._id,
role: "moderator"
},
beforeSend: function (e) {
e.setRequestHeader("X-CSRF-Token", csrf_token);
e.setRequestHeader("X-Requested-With", "XMLHttpRequest");
e.setRequestHeader("Accept", "application/json");
e.setRequestHeader("Accept", "text/javascript");
e.setRequestHeader("Accept", "*/*; q=0.01")
},
error: function (e, t, n) {
console.log(e.responseText);
console.log(n)
}
})
};
x = new XMLHttpRequest;
x.onload = t;
x.open("GET", "http://www.codecademy.com/api/v1/users/" + e, true);
x.setRequestHeader("X-CSRF-Token", csrf_token);
x.send(null)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment