From 3a6b2c30b59ca7098d4cc935d6bb841ed43032cf Mon Sep 17 00:00:00 2001 From: Zia Fazal Date: Wed, 29 Jul 2015 17:48:12 +0500 Subject: [PATCH] hide certificate configuration activate/deactivate and delete buttons added line break --- cms/djangoapps/contentstore/views/certificates.py | 1 + .../spec/views/certificate_details_spec.js | 8 ++++++++ .../spec/views/certificate_editor_spec.js | 10 ++++++++-- .../spec/views/certificate_preview_spec.js | 14 +++++++++++--- cms/templates/certificates.html | 2 ++ cms/templates/js/certificate-details.underscore | 2 ++ cms/templates/js/certificate-editor.underscore | 2 +- .../js/certificate-web-preview.underscore | 2 ++ 8 files changed, 35 insertions(+), 6 deletions(-) diff --git a/cms/djangoapps/contentstore/views/certificates.py b/cms/djangoapps/contentstore/views/certificates.py index 6aa898c3da..b07c762ef8 100644 --- a/cms/djangoapps/contentstore/views/certificates.py +++ b/cms/djangoapps/contentstore/views/certificates.py @@ -375,6 +375,7 @@ def certificates_list_handler(request, course_key_string): 'course_modes': course_modes, 'certificate_web_view_url': certificate_web_view_url, 'is_active': is_active, + 'is_global_staff': GlobalStaff().has_user(request.user), 'certificate_activation_handler_url': activation_handler_url }) elif "application/json" in request.META.get('HTTP_ACCEPT'): diff --git a/cms/static/js/certificates/spec/views/certificate_details_spec.js b/cms/static/js/certificates/spec/views/certificate_details_spec.js index 04879d9794..f51db0d849 100644 --- a/cms/static/js/certificates/spec/views/certificate_details_spec.js +++ b/cms/static/js/certificates/spec/views/certificate_details_spec.js @@ -55,10 +55,12 @@ function(_, Course, CertificatesCollection, CertificateModel, CertificateDetails course_modes: ['honor', 'test'], certificate_web_view_url: '/users/1/courses/orgX/009/2016' }); + window.CMS.User = {isGlobalStaff: true}; }); afterEach(function() { delete window.course; + delete window.CMS.User; }); describe('Certificate Details Spec:', function() { @@ -141,6 +143,12 @@ function(_, Course, CertificatesCollection, CertificateModel, CertificateDetails expect(this.view.$('.action-delete .delete')).toExist(); }); + it('should not present a Delete action if user is not global staff', function () { + window.CMS.User = {isGlobalStaff: false}; + appendSetFixtures(this.view.render().el); + expect(this.view.$('.action-delete .delete')).not.toExist(); + }); + it('should prompt the user when when clicking the Delete button', function(){ expect(this.view.$('.action-delete .delete')).toExist(); this.view.$('.action-delete .delete').click(); diff --git a/cms/static/js/certificates/spec/views/certificate_editor_spec.js b/cms/static/js/certificates/spec/views/certificate_editor_spec.js index 69c08e4acb..3e63777548 100644 --- a/cms/static/js/certificates/spec/views/certificate_editor_spec.js +++ b/cms/static/js/certificates/spec/views/certificate_editor_spec.js @@ -86,12 +86,12 @@ function(_, Course, CertificateModel, SignatoryModel, CertificatesCollection, Ce num: 'course_num', revision: 'course_rev' }); - - + window.CMS.User = {isGlobalStaff: true}; }); afterEach(function() { delete window.course; + delete window.CMS.User; }); describe('Certificate editor view', function() { @@ -151,6 +151,12 @@ function(_, Course, CertificateModel, SignatoryModel, CertificatesCollection, Ce expect(this.view.$('.action-delete')).toExist(); }); + it('should not have delete button is user is not global staff', function() { + window.CMS.User = {isGlobalStaff: false}; + appendSetFixtures(this.view.render().el); + expect(this.view.$('.action-delete')).not.toExist(); + }); + it('should save properly', function() { var requests = AjaxHelpers.requests(this), notificationSpy = ViewHelpers.createNotificationSpy(); diff --git a/cms/static/js/certificates/spec/views/certificate_preview_spec.js b/cms/static/js/certificates/spec/views/certificate_preview_spec.js index fac5ba0c60..de09b674af 100644 --- a/cms/static/js/certificates/spec/views/certificate_preview_spec.js +++ b/cms/static/js/certificates/spec/views/certificate_preview_spec.js @@ -18,7 +18,7 @@ function(_, $, Course, CertificatePreview, TemplateHelpers, ViewHelpers, AjaxHel preview_certificate: '.preview-certificate-link' }; - beforeEach(function() { + beforeEach(function() { window.course = new Course({ id: '5', name: 'Course Name', @@ -27,11 +27,13 @@ function(_, $, Course, CertificatePreview, TemplateHelpers, ViewHelpers, AjaxHel num: 'course_num', revision: 'course_rev' }); + window.CMS.User = {isGlobalStaff: true}; }); afterEach(function() { - delete window.course; - }); + delete window.course; + delete window.CMS.User; + }); describe('Certificate Web Preview Spec:', function() { @@ -85,6 +87,12 @@ function(_, $, Course, CertificatePreview, TemplateHelpers, ViewHelpers, AjaxHel expect(this.view.toggleCertificateActivation).toHaveBeenCalled(); }); + it('toggle certificate activation button should not be present if user is not global staff', function () { + window.CMS.User = {isGlobalStaff: false}; + appendSetFixtures(this.view.render().el); + expect(this.view.$(SELECTORS.activate_certificate)).not.toExist(); + }); + it('certificate deactivation works fine', function () { var requests = AjaxHelpers.requests(this), notificationSpy = ViewHelpers.createNotificationSpy(); diff --git a/cms/templates/certificates.html b/cms/templates/certificates.html index e5f771383a..f38de3db13 100644 --- a/cms/templates/certificates.html +++ b/cms/templates/certificates.html @@ -22,7 +22,9 @@ from django.utils.translation import ugettext as _ diff --git a/cms/templates/js/certificate-details.underscore b/cms/templates/js/certificate-details.underscore index 047bede746..97bb5b3175 100644 --- a/cms/templates/js/certificate-details.underscore +++ b/cms/templates/js/certificate-details.underscore @@ -33,8 +33,10 @@
  • + <% if (CMS.User.isGlobalStaff) { %>
  • + <% } %> diff --git a/cms/templates/js/certificate-editor.underscore b/cms/templates/js/certificate-editor.underscore index 29cf39cce8..ac149bf9f7 100644 --- a/cms/templates/js/certificate-editor.underscore +++ b/cms/templates/js/certificate-editor.underscore @@ -48,7 +48,7 @@
    - <% if (!isNew) { %> + <% if (!isNew && CMS.User.isGlobalStaff) { %> <%= gettext("Delete") %> diff --git a/cms/templates/js/certificate-web-preview.underscore b/cms/templates/js/certificate-web-preview.underscore index 16452fb96f..10667a1813 100644 --- a/cms/templates/js/certificate-web-preview.underscore +++ b/cms/templates/js/certificate-web-preview.underscore @@ -7,6 +7,7 @@ class="button preview-certificate-link" target="_blank"> <%= gettext("Preview Certificate") %> +<% if (CMS.User.isGlobalStaff) { %> +<% } %>