Commit c341975b by brianhw

Merge pull request #1072 from MITx/feature/brian/dashboard-manage-mods

Feature/brian/dashboard manage mods
parents 706a8253 8d0eb7f1
import logging
from django.db import models
from django.contrib.auth.models import User
import logging
from courseware.courses import get_course_by_id
FORUM_ROLE_ADMINISTRATOR = 'Administrator'
FORUM_ROLE_MODERATOR = 'Moderator'
FORUM_ROLE_COMMUNITY_TA = 'Community TA'
FORUM_ROLE_STUDENT = 'Student'
class Role(models.Model):
name = models.CharField(max_length=30, null=False, blank=False)
users = models.ManyToManyField(User, related_name="roles")
......@@ -15,8 +21,8 @@ class Role(models.Model):
def inherit_permissions(self, role): # TODO the name of this method is a little bit confusing,
# since it's one-off and doesn't handle inheritance later
if role.course_id and role.course_id != self.course_id:
logging.warning("%s cannot inheret permissions from %s due to course_id inconsistency" %
(self, role))
logging.warning("{0} cannot inherit permissions from {1} due to course_id inconsistency", \
self, role)
for per in role.permissions.all():
self.add_permission(per)
......@@ -25,10 +31,10 @@ class Role(models.Model):
def has_permission(self, permission):
course = get_course_by_id(self.course_id)
if self.name == "Student" and \
if self.name == FORUM_ROLE_STUDENT and \
(permission.startswith('edit') or permission.startswith('update') or permission.startswith('create')) and \
(not course.forum_posts_allowed):
return False
return False
return self.permissions.filter(name=permission).exists()
......
import time
from collections import defaultdict
from importlib import import_module
import logging
import time
import urllib
from courseware.models import StudentModuleCache
from courseware.module_render import get_module
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.search import path_to_location
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import connection
from django.http import HttpResponse
from django.utils import simplejson
from django.db import connection
from django.conf import settings
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from django_comment_client.permissions import check_permissions_by_view
from django_comment_client.models import Role
from django_comment_client.permissions import check_permissions_by_view
from mitxmako import middleware
import logging
import operator
import itertools
import urllib
import pystache_custom as pystache
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.search import path_to_location
# TODO these should be cached via django's caching rather than in-memory globals
_FULLMODULES = None
......@@ -47,9 +41,16 @@ def get_role_ids(course_id):
staff = list(User.objects.filter(is_staff=True).values_list('id', flat=True))
roles_with_ids = {'Staff': staff}
for role in roles:
roles_with_ids[role.name] = list(role.users.values_list('id', flat=True))
roles_with_ids[role.name] = list(role.users.values_list('id', flat=True))
return roles_with_ids
def has_forum_access(uname, course_id, rolename):
try:
role = Role.objects.get(name=rolename, course_id=course_id)
except Role.DoesNotExist:
return False
return role.users.filter(username=uname).exists()
def get_full_modules():
global _FULLMODULES
if not _FULLMODULES:
......@@ -132,8 +133,6 @@ def initialize_discussion_info(course):
return
course_id = course.id
url_course_id = course_id.replace('/', '_').replace('.', '_')
all_modules = get_full_modules()[course_id]
discussion_id_map = {}
......
......@@ -56,7 +56,8 @@ function goto( mode)
%if settings.MITX_FEATURES.get('ENABLE_PSYCHOMETRICS'):
<a href="#" onclick="goto('Psychometrics');" class="${modeflag.get('Psychometrics')}">Psychometrics</a> |
%endif
<a href="#" onclick="goto('Admin');" class="${modeflag.get('Admin')}">Admin</a> ]
<a href="#" onclick="goto('Admin');" class="${modeflag.get('Admin')}">Admin</a> |
<a href="#" onclick="goto('Forum Admin');" class="${modeflag.get('Forum Admin')}">Forum Admin</a> ]
</h2>
<div style="text-align:right" id="djangopid">${djangopid}</div>
......@@ -134,6 +135,34 @@ function goto( mode)
%endif
%endif
##-----------------------------------------------------------------------------
%if modeflag.get('Forum Admin'):
%if instructor_access:
<hr width="40%" style="align:left">
<p>
<input type="submit" name="action" value="List course forum admins">
<p>
<input type="text" name="forumadmin"> <input type="submit" name="action" value="Remove forum admin">
<input type="submit" name="action" value="Add forum admin">
<hr width="40%" style="align:left">
%endif
%if instructor_access or forum_admin_access:
<p>
<input type="submit" name="action" value="List course forum moderators">
<input type="submit" name="action" value="List course forum community TAs">
<p>
<input type="text" name="forummoderator">
<input type="submit" name="action" value="Remove forum moderator">
<input type="submit" name="action" value="Add forum moderator">
<input type="submit" name="action" value="Remove forum community TA">
<input type="submit" name="action" value="Add forum community TA">
<hr width="40%" style="align:left">
%else:
<p>User requires forum administrator privileges to perform administration tasks. See instructor.</p>
%endif
%endif
</form>
##-----------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment