Permalink
Browse files

Merge pull request #127 from ndarville/manage-users

Merged manage-users branch; implements unpolished co-editor feature
  • Loading branch information...
ndarville committed May 3, 2014
2 parents 28daef7 + 1e1bc93 commit e8bed6ee23193e4b2a03556a0d27f1579b1a98d5
View
@@ -15,6 +15,7 @@ env:
- PIP_USE_MIRRORS=true
install:
- pip install elementtree --allow-external elementtree --allow-unverified elementtree
- pip install -r requirements.txt
# - pip install django==$DJANGO --quiet
- pip install coveralls radon
View
@@ -24,6 +24,7 @@ def get_perm(codename):
get_perm('move_thread'),
get_perm('lock_thread'),
# Post
get_perm('appoint_coeditor'),
get_perm('remove_post'),
get_perm('moderate_post'),
# User
@@ -54,6 +54,7 @@
"post_count": 1,
"latest_reply_date": "2012-12-20T07:35:18.134",
"is_removed": false,
"coeditors": [],
"bookmarker": [],
"is_locked": false
}
@@ -72,6 +73,7 @@
"post_count": 1,
"latest_reply_date": "2012-12-20T07:33:25.410",
"is_removed": false,
"coeditors": [],
"bookmarker": [],
"is_locked": false
}
@@ -90,6 +92,7 @@
"post_count": 1,
"latest_reply_date": "2012-12-20T07:33:06.993",
"is_removed": false,
"coeditors": [],
"bookmarker": [],
"is_locked": false
}
@@ -106,7 +109,6 @@
"creation_date": "2012-12-20T07:33:06.993",
"is_removed": false,
"thanks": [],
"co_editors": [],
"content_html": "<p>This thread will be merged with Merge Thread 2.</p>"
}
},
@@ -122,7 +124,6 @@
"creation_date": "2012-12-20T07:33:25.410",
"is_removed": false,
"thanks": [],
"co_editors": [],
"content_html": "<p>This thread will be merged with Merge Thread 1.</p>"
}
},
@@ -138,7 +139,6 @@
"creation_date": "2012-12-20T07:35:18.134",
"is_removed": false,
"thanks": [],
"co_editors": [],
"content_html": "<p>This thread and its posts will be subjected to the following operations:</p>\n<h2>Thread</h2>\n<ul>\n<li>Lock</li>\n<li>Merge</li>\n<li>Moderate</li>\n<li>Remove</li>\n<li>Sticky</li>\n</ul>\n<h2>Post</h2>\n<ul>\n<li>Edit</li>\n<li>Reply</li>\n<li>Remove</li>\n</ul>"
}
}
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -13,6 +13,7 @@
"is_locked": false,
"latest_reply_date": "2012-10-08T14:58:53.375",
"is_removed": false,
"coeditors": [],
"bookmarker": []
}
},
@@ -30,6 +31,7 @@
"is_locked": false,
"latest_reply_date": "2012-10-08T14:58:53.375",
"is_removed": false,
"coeditors": [],
"bookmarker": []
}
},
@@ -47,6 +49,7 @@
"is_locked": false,
"latest_reply_date": "2012-10-08T14:58:53.375",
"is_removed": false,
"coeditors": [],
"bookmarker": []
}
},
@@ -64,6 +67,7 @@
"is_locked": false,
"latest_reply_date": "2012-10-08T14:58:53.375",
"is_removed": false,
"coeditors": [],
"bookmarker": []
}
},
@@ -81,6 +85,7 @@
"is_locked": false,
"latest_reply_date": "2012-10-08T14:58:53.375",
"is_removed": false,
"coeditors": [],
"bookmarker": []
}
}
View
@@ -81,6 +81,9 @@ class Thread(models.Model):
is_locked = models.BooleanField(default=False)
is_removed = models.BooleanField(default=False)
# poll = models.ForeignKey(Poll, null=True, blank=True)
coeditors = models.ManyToManyField(User, null=True, blank=True,
verbose_name="co-editor",
related_name="coeditors")
bookmarker = models.ManyToManyField(User, null=True, blank=True,
related_name="bookmarks")
subscriber = models.ManyToManyField(User, null=True, blank=True,
@@ -91,12 +94,13 @@ class Thread(models.Model):
class Meta:
ordering = ["-creation_date"]
permissions = (
("remove_thread", "Remove (and restore) threads"),
("moderate_thread", "Edit thread titles"),
("merge_thread", "Merge multiple threads together"),
("sticky_thread", "Stick a thread to the top of the thread list"),
("move_thread", "Move a thread to another category"),
("lock_thread", "Lock (and unlock) threads"),
("appoint_coeditor", "Appoint co-editors for threads"),
("remove_thread", "Remove (and restore) threads"),
("moderate_thread", "Edit thread titles"),
("merge_thread", "Merge multiple threads together"),
("sticky_thread", "Stick a thread to the top of the thread list"),
("move_thread", "Move a thread to another category"),
("lock_thread", "Lock (and unlock) threads"),
# ("ban_user_in_thread",
# "Ban user from posting in thread permanently"),
# ("timeout_user_in_thread",
@@ -121,9 +125,6 @@ class Post(models.Model):
content_html = models.TextField()
author = models.ForeignKey(User)
thread = models.ForeignKey(Thread)
co_editors = models.ManyToManyField(User, null=True, blank=True,
verbose_name="co-editor",
related_name="co-editors")
agrees = models.ManyToManyField(User, null=True, blank=True,
related_name="agrees")
thanks = models.ManyToManyField(User, null=True, blank=True,
@@ -135,8 +136,8 @@ class Post(models.Model):
class Meta:
ordering = ["creation_date"]
permissions = (
("moderate_post", "Can edit the post of others"),
("remove_post", "Can remove posts"),
("moderate_post", "Can edit the post of others"),
("remove_post", "Can remove posts"),
)
def __unicode__(self):
View
@@ -379,14 +379,31 @@ input[type="submit"] {
overflow: hidden;
}
/**** *****
***** ACCOUNTS *****
***** ****/
#account-form {
/**** *****
***** ACCOUNTS, MANAGE *****
***** ****/
#left-aligned-button-group {
text-align: left;
}
.user-list {
display: block;
width: 90%;
margin: 1em auto 0 auto;
}
.user-list li {
list-style: none;
margin-top: 1em;
}
#account-form,
#search-form {
text-align: center;
}
#account-form label {
#account-form label,
#search-form label {
display: none;
}
@@ -396,7 +413,8 @@ input[type="submit"] {
#account-form input[type="email"],
#account-form input[type="text"],
#account-form input[type*="password"] {
#account-form input[type="password"],
#search-form input[type="search"] {
padding-left: 35px; /** Revise */
min-width: 60%;
max-width: 95%;
@@ -408,18 +426,24 @@ input[type="submit"] {
background-position: 5px 50%;
}
#account-form input[name="email"] {
#account-form input[type="email"] {
background: url(/static/glyphish/18-envelope.png) no-repeat left;
background-size: 1.5em;
background-position: 5px 50%;
}
#account-form input[name*="password"] {
#account-form input[type="password"] {
background: url(/static/glyphish/54-lock.png) no-repeat left;
background-size: 1.25em;
background-position: 7px 50%;
}
#search-form input[type="search"] {
background: url(/static/glyphish/06-magnify.png) no-repeat left;
background-size: 1.25em;
background-position: 7px 50%;
}
form p.checkbox { }
form p.checkbox label {
width: 90%;
@@ -499,12 +523,16 @@ legend {
text-align: center;
}
.remove {
#content-body .remove {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
#content-body .remove:hover {
background-color: rgba(0,0,0, .1);
}
#content-body .unsubscribe,
#content-body .count,
#content-body .remove {
@@ -916,9 +944,11 @@ nor with different rules */
/**** *****
***** CREATE, REPLY & EDIT *****
***** ****/
input[type=email],
input[type=password],
input[type=text],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="text"],
textarea,
#title-form,
#id-form {
@@ -936,9 +966,11 @@ textarea,
-ms-box-sizing: border-box; /** May not work for IE7- */
}
input[type=email],
input[type=password],
input[type=text],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="text"],
textarea,
#title-form,
#id-form {
@@ -0,0 +1,63 @@
$(document).ready(function() {
// This CSRF token allows us to make POST requests
$(document).ajaxSend(function(event, xhr, settings) {
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
function sameOrigin(url) {
// url could be relative or scheme relative or absolute
var host = document.location.host, // host + port
protocol = document.location.protocol,
sr_origin = '//' + host,
origin = protocol + sr_origin;
// Allow absolute or scheme relative URLs to same origin
return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
(url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
// or any other URL that isn't scheme relative or absolute i.e relative.
!(/^(\/\/|http:|https:).*/.test(url));
}
function safeMethod(method) {
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
if (!safeMethod(settings.type) && sameOrigin(settings.url)) {
xhr.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
}
});
$('.js').on('click', function(e) {
// Only perform the following if user is logged in,
// detected by checking for a "Log out" in navigation.
if ($('.last:contains("Log Out")').length) {
// Overrule default nonjs action when submit button is clicked
// to allow handling the the logic with our JavaScript instead.
e.preventDefault();
var $this = $(this),
object_id = $("#thread-id").val(),
user_id = this.id,
action = $this.text()
$.post("/thread/co-editors/js/", {
object_id: object_id,
user_id: user_id,
action: action
},
function(data) {
$this.text(data);
});
}
});
});
@@ -50,11 +50,14 @@
{% if user != post.author and perms.forum.moderate_post %} {# Convert to elif #}
<a class="button" href="{% url forum.views.edit post.id %}">Moderate</a>
{% endif %}
{% comment %}
{% if forloop.first and user == post_author %}
<a class="button" href="/thread/{{ thread.id }}/co-editor">Manage Co-Editors</a>
{% if forloop.first %}
{% if user == post_author or perms.forum.appoint_coeditor %}
<a class="button" href="{% url forum.views.manage_coeditors thread.id %}">Manage Co-Editors</a>
{% endif %}
{% if user != post_author and thread in user.coeditors_set.all %}
<a class="button" href="{% url forum.views.edit post.id %}">
{% endif %}
{% endif %}
{% endcomment %}
{% endif %}
</div>
Oops, something went wrong.

0 comments on commit e8bed6e

Please sign in to comment.