From 52ac0e03ae65ef7aeb07f1dc9811e034c240a03f Mon Sep 17 00:00:00 2001
From: Umar Asghar <umar.asghar@arbisoft.com>
Date: Thu, 29 Oct 2020 13:30:24 +0500
Subject: [PATCH] remove users listing and staff listing download csv from the
 sysadmin

---
 .../decisions/0001-sysadmin-dashboard.rst     |  3 +-
 .../0002-deprecate-sysadmin-dashboard-adr.rst |  4 +-
 lms/djangoapps/dashboard/sysadmin.py          | 70 +------------------
 lms/templates/sysadmin_dashboard.html         | 11 ---
 4 files changed, 6 insertions(+), 82 deletions(-)

diff --git a/lms/djangoapps/dashboard/decisions/0001-sysadmin-dashboard.rst b/lms/djangoapps/dashboard/decisions/0001-sysadmin-dashboard.rst
index a8e76e09d47..a6223869030 100644
--- a/lms/djangoapps/dashboard/decisions/0001-sysadmin-dashboard.rst
+++ b/lms/djangoapps/dashboard/decisions/0001-sysadmin-dashboard.rst
@@ -30,8 +30,7 @@ edX installations using Shibboleth and certificate-based authentication.
 The courses tabs manages adding/updating courses from git, deleting courses, and provides course listing information,
 including commit hash, date and author for course imported from git.
 
-The Staffing tab provides a view of staffing and enrollment in courses that include an option to download the data
-as a csv.
+The Staffing tab provides a view of staffing and enrollment in courses.
 
 The Gitlogs tab provides a view into the import log of courses from git repositories. It is convenient for allowing
 course teams to see what may be wrong wit their xml. This is the only view that allows permits access by course
diff --git a/lms/djangoapps/dashboard/decisions/0002-deprecate-sysadmin-dashboard-adr.rst b/lms/djangoapps/dashboard/decisions/0002-deprecate-sysadmin-dashboard-adr.rst
index 320c9d6c490..bb6a33cb2c7 100644
--- a/lms/djangoapps/dashboard/decisions/0002-deprecate-sysadmin-dashboard-adr.rst
+++ b/lms/djangoapps/dashboard/decisions/0002-deprecate-sysadmin-dashboard-adr.rst
@@ -31,7 +31,7 @@ would need to be added and/or moved into the cms application
 
 3. Delete a course
 
-   https://github.com/edx/edx-platform/blob/master/lms/djangoapps/dashboard/sysadmin.py#L383-L408
+   https://github.com/edx/edx-platform/blob/b4556a4bec/lms/djangoapps/dashboard/sysadmin.py#L344-L369
 
 
 These APIs can be removed entirely, as they are adequately covered by existing functionality:
@@ -43,7 +43,7 @@ These APIs can be removed entirely, as they are adequately covered by existing f
 
 2. Staffing and Enrollment
 
-   https://github.com/edx/edx-platform/blob/master/lms/djangoapps/dashboard/sysadmin.py#L419-L477
+   https://github.com/edx/edx-platform/blob/b4556a4bec/lms/djangoapps/dashboard/sysadmin.py#L380-L413
 
    This functionality may be redundant to features in the Insights application.
 
diff --git a/lms/djangoapps/dashboard/sysadmin.py b/lms/djangoapps/dashboard/sysadmin.py
index 4912a89bdbd..f55293eb824 100644
--- a/lms/djangoapps/dashboard/sysadmin.py
+++ b/lms/djangoapps/dashboard/sysadmin.py
@@ -10,13 +10,12 @@ import os
 import subprocess
 
 import mongoengine
-import unicodecsv as csv
 from django.conf import settings
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.models import User
 from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
 from django.db import IntegrityError
-from django.http import Http404, HttpResponse
+from django.http import Http404
 from django.utils.decorators import method_decorator
 from django.utils.html import escape
 from django.utils.translation import ugettext as _
@@ -71,38 +70,6 @@ class SysadminDashboardView(TemplateView):
 
         return self.def_ms.get_courses()
 
-    def return_csv(self, filename, header, data):
-        """
-        Convenient function for handling the http response of a csv.
-        data should be iterable and is used to stream object over http
-        """
-
-        csv_file = StringIO()
-        writer = csv.writer(csv_file, dialect='excel', quotechar='"',
-                            quoting=csv.QUOTE_ALL)
-
-        writer.writerow(header)
-
-        # Setup streaming of the data
-        def read_and_flush():
-            """Read and clear buffer for optimization"""
-            csv_file.seek(0)
-            csv_data = csv_file.read()
-            csv_file.seek(0)
-            csv_file.truncate()
-            return csv_data
-
-        def csv_data():
-            """Generator for handling potentially large CSVs"""
-            for row in data:
-                writer.writerow(row)
-            csv_data = read_and_flush()
-            yield csv_data
-        response = HttpResponse(csv_data(), content_type='text/csv')
-        response['Content-Disposition'] = u'attachment; filename={0}'.format(
-            filename)
-        return response
-
 
 class Users(SysadminDashboardView):
     """
@@ -211,13 +178,7 @@ class Users(SysadminDashboardView):
         action = request.POST.get('action', '')
         track.views.server_track(request, action, {}, page='user_sysdashboard')
 
-        if action == 'download_users':
-            header = [_('username'), _('email'), ]
-            data = ([u.username, u.email] for u in
-                    (User.objects.all().iterator()))
-            return self.return_csv('users_{0}.csv'.format(
-                request.META['SERVER_NAME']), header, data)
-        elif action == 'create_user':
+        if action == 'create_user':
             uname = request.POST.get('student_uname', '').strip()
             name = request.POST.get('student_fullname', '').strip()
             password = request.POST.get('student_password', '').strip()
@@ -419,7 +380,7 @@ class Courses(SysadminDashboardView):
 class Staffing(SysadminDashboardView):
     """
     The status view provides a view of staffing and enrollment in
-    courses that include an option to download the data as a csv.
+    courses.
     """
 
     def get(self, request):
@@ -451,31 +412,6 @@ class Staffing(SysadminDashboardView):
         }
         return render_to_response(self.template_name, context)
 
-    def post(self, request):
-        """Handle all actions from staffing and enrollment view"""
-
-        action = request.POST.get('action', '')
-        track.views.server_track(request, action, {},
-                                 page='staffing_sysdashboard')
-
-        if action == 'get_staff_csv':
-            data = []
-            roles = [CourseInstructorRole, CourseStaffRole, ]
-
-            for course in self.get_courses():
-                for role in roles:
-                    for user in role(course.id).users_with_role():
-                        datum = [course.id, role, user.username, user.email,
-                                 user.profile.name.encode('utf-8')]
-                        data.append(datum)
-            header = [_('course_id'),
-                      _('role'), _('username'),
-                      _('email'), _('full_name'), ]
-            return self.return_csv('staff_{0}.csv'.format(
-                request.META['SERVER_NAME']), header, data)
-
-        return self.get(request)
-
 
 class GitLogs(TemplateView):
     """
diff --git a/lms/templates/sysadmin_dashboard.html b/lms/templates/sysadmin_dashboard.html
index a0d46d64c35..01e31fc2197 100644
--- a/lms/templates/sysadmin_dashboard.html
+++ b/lms/templates/sysadmin_dashboard.html
@@ -91,11 +91,6 @@ textarea {
     </div>
 
 	<hr />
-    <p>
-      <button type="submit" name="action" value="download_users" style="width: 350px;">
-		${_('Download list of all users (csv file)')}
-	  </button>
-    </p>
 
     <p>
     <button type="submit" name="action" value="repair_eamap" style="width: 350px;">
@@ -112,12 +107,6 @@ textarea {
 <p>${_("Go to each individual course's Instructor dashboard to manage course enrollment.")}</p>
 <hr />
 
-<h3>${_('Manage course staff and instructors')}</h3><br/>
-<form name="action" method="POST">
-  <input type="hidden" name="csrfmiddlewaretoken" value="${ csrf_token }" />
-  <button type="submit" name="action" value="get_staff_csv">${_('Download staff and instructor list (csv file)')}</button>
-</form>
-
 %endif
 
 %if modeflag.get('courses'):
-- 
GitLab