mirror of https://github.com/zulip/zulip.git
support: Add support for scrubbing realm.
This commit is contained in:
parent
f6203f068b
commit
6c58603eaf
|
@ -341,7 +341,9 @@ class TestSupportEndpoint(ZulipTestCase):
|
|||
'<option value="2" >Limited</option>',
|
||||
'input type="number" name="discount" value="None"',
|
||||
'<option value="active" selected>Active</option>',
|
||||
'<option value="deactive" >Deactive</option>'], result)
|
||||
'<option value="deactive" >Deactive</option>',
|
||||
'scrub-realm-button">',
|
||||
'data-string-id="zulip"'], result)
|
||||
|
||||
def check_lear_realm_result(result: HttpResponse) -> None:
|
||||
self.assert_in_success_response(['<input type="hidden" name="realm_id" value="3"', 'Lear & Co.</h3>',
|
||||
|
@ -349,7 +351,9 @@ class TestSupportEndpoint(ZulipTestCase):
|
|||
'<option value="2" >Limited</option>',
|
||||
'input type="number" name="discount" value="None"',
|
||||
'<option value="active" selected>Active</option>',
|
||||
'<option value="deactive" >Deactive</option>'], result)
|
||||
'<option value="deactive" >Deactive</option>',
|
||||
'scrub-realm-button">',
|
||||
'data-string-id="lear"'], result)
|
||||
|
||||
cordelia_email = self.example_email("cordelia")
|
||||
self.login(cordelia_email)
|
||||
|
@ -441,6 +445,26 @@ class TestSupportEndpoint(ZulipTestCase):
|
|||
m.assert_called_once_with(get_realm("lear"))
|
||||
self.assert_in_success_response(["Lear & Co. reactivated."], result)
|
||||
|
||||
def test_scrub_realm(self) -> None:
|
||||
cordelia_email = self.example_email("cordelia")
|
||||
self.login(cordelia_email)
|
||||
|
||||
result = self.client_post("/activity/support", {"realm_id": "3", "discount": "25"})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result["Location"], "/login/")
|
||||
|
||||
iago_email = self.example_email("iago")
|
||||
self.login(iago_email)
|
||||
|
||||
with mock.patch("analytics.views.do_scrub_realm") as m:
|
||||
result = self.client_post("/activity/support", {"realm_id": "3", "scrub_realm": "scrub_realm"})
|
||||
m.assert_called_once_with(get_realm("lear"))
|
||||
self.assert_in_success_response(["Lear & Co. scrubbed"], result)
|
||||
|
||||
with mock.patch("analytics.views.do_scrub_realm") as m:
|
||||
result = self.client_post("/activity/support", {"realm_id": "3"})
|
||||
m.assert_not_called()
|
||||
|
||||
class TestGetChartDataHelpers(ZulipTestCase):
|
||||
# last_successful_fill is in analytics/models.py, but get_chart_data is
|
||||
# the only function that uses it at the moment
|
||||
|
|
|
@ -40,7 +40,7 @@ from zerver.lib.realm_icon import realm_icon_url
|
|||
from zerver.views.invite import get_invitee_emails_set
|
||||
from zerver.lib.subdomains import get_subdomain_from_hostname
|
||||
from zerver.lib.actions import do_change_plan_type, do_deactivate_realm, \
|
||||
do_reactivate_realm
|
||||
do_reactivate_realm, do_scrub_realm
|
||||
|
||||
if settings.BILLING_ENABLED:
|
||||
from corporate.lib.stripe import attach_discount_to_realm, get_discount_for_realm
|
||||
|
@ -1060,6 +1060,12 @@ def support(request: HttpRequest) -> HttpResponse:
|
|||
do_deactivate_realm(realm)
|
||||
context["message"] = "{} deactivated.".format(realm.name)
|
||||
|
||||
scrub_realm = request.POST.get("scrub_realm", None)
|
||||
if scrub_realm is not None:
|
||||
if scrub_realm == "scrub_realm":
|
||||
do_scrub_realm(realm)
|
||||
context["message"] = "{} scrubbed.".format(realm.name)
|
||||
|
||||
query = request.GET.get("q", None)
|
||||
if query:
|
||||
key_words = get_invitee_emails_set(query)
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
const fs = require("fs");
|
||||
const { JSDOM } = require("jsdom");
|
||||
const template = fs.readFileSync("templates/analytics/support.html", "utf-8");
|
||||
const dom = new JSDOM(template, { pretendToBeVisual: true });
|
||||
const document = dom.window.document;
|
||||
|
||||
var jquery_init;
|
||||
global.$ = (f) => {jquery_init = f;};
|
||||
zrequire('support', "js/analytics/support");
|
||||
set_global('$', global.make_zjquery());
|
||||
|
||||
run_test('scrub_realm', () => {
|
||||
jquery_init();
|
||||
var click_handler = $('body').get_on_handler('click', '.scrub-realm-button');
|
||||
assert.equal(typeof click_handler, 'function');
|
||||
|
||||
assert.equal(document.querySelectorAll(".scrub-realm-button").length, 2);
|
||||
});
|
|
@ -0,0 +1,10 @@
|
|||
$(function () {
|
||||
$("body").on("click", ".scrub-realm-button", function (e) {
|
||||
e.preventDefault();
|
||||
var string_id = $(this).data("string-id");
|
||||
var message = 'Do you really want to scrub the realm "' + string_id + '"? This action is irreversible.';
|
||||
if (confirm(message)) { // eslint-disable-line no-alert
|
||||
this.form.submit();
|
||||
}
|
||||
});
|
||||
});
|
|
@ -75,6 +75,11 @@ tr.admin td:first-child {
|
|||
top: -25px;
|
||||
}
|
||||
|
||||
.scrub-realm-form {
|
||||
position: relative;
|
||||
top: -50px;
|
||||
}
|
||||
|
||||
.support-submit-button {
|
||||
position: relative;
|
||||
top: -5px;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
{% block customhead %}
|
||||
{{ super() }}
|
||||
{{ render_bundle('activity') }}
|
||||
{{ render_bundle('support') }}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -32,7 +33,7 @@
|
|||
|
||||
<div id="query-results">
|
||||
{% for user in users %}
|
||||
<div class="support-query-result">
|
||||
<div class="support-query-result new-style">
|
||||
<span class="label">user</span>
|
||||
<h3>{{ user.full_name }}</h3>
|
||||
<b>Email</b>: {{ user.email }}<br>
|
||||
|
@ -75,13 +76,19 @@
|
|||
<input type="number" name="discount" value="{{user.realm.default_discount}}" required>
|
||||
<button type="submit" class="btn btn-small support-submit-button">Update</button>
|
||||
</form>
|
||||
<form method="POST" class="scrub-realm-form">
|
||||
{{ csrf_input }}
|
||||
<input type="hidden" name="realm_id" value="{{ user.realm.id }}" />
|
||||
<input type="hidden" name="scrub_realm" value="scrub_realm" />
|
||||
<button data-string-id="{{user.realm.string_id}}" class="button rounded btn-danger small scrub-realm-button">Scrub realm</button>
|
||||
</form>
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{% for realm in realms %}
|
||||
<div class="support-query-result">
|
||||
<div class="support-query-result new-style">
|
||||
<span class="label">realm</span>
|
||||
<h3><img src="{{ realm.realm_icon_url }}" class="support-realm-icon"> {{ realm.name }}</h3>
|
||||
<b>URL</b>: <a target="_blank" href="{{ realm.uri }}">{{ realm.uri }}</a><br>
|
||||
|
@ -116,6 +123,12 @@
|
|||
<input type="number" name="discount" value="{{ realm.default_discount}}" required>
|
||||
<button type="submit" class="btn btn-small support-submit-button">Update</button>
|
||||
</form>
|
||||
<form method="POST" class="scrub-realm-form">
|
||||
{{ csrf_input }}
|
||||
<input type="hidden" name="realm_id" value="{{ realm.id }}" />
|
||||
<input type="hidden" name="scrub_realm" value="scrub_realm" />
|
||||
<button data-string-id="{{realm.string_id}}" class="button rounded btn-danger small scrub-realm-button">Scrub realm</button>
|
||||
</form>
|
||||
<hr>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
|
|
@ -82,6 +82,10 @@
|
|||
"./node_modules/jquery-validation/dist/jquery.validate.min.js",
|
||||
"./static/js/portico/signup.js"
|
||||
],
|
||||
"support": [
|
||||
"./static/js/analytics/support.js",
|
||||
"./static/styles/app_components.scss"
|
||||
],
|
||||
"dev-login": "./static/js/portico/dev-login.js",
|
||||
"email-log": "./static/js/portico/email_log.js",
|
||||
"stats": [
|
||||
|
|
Loading…
Reference in New Issue