mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 08:56:10 +00:00
/json/users: Replace email with user_id in API to reactivate user.
This commit is contained in:
committed by
Tim Abbott
parent
06e7e933cc
commit
4162e61f33
@@ -324,10 +324,10 @@ exports.set_up = function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#inactive_bots_list").on("click", "button.reactivate_bot", function (e) {
|
$("#inactive_bots_list").on("click", "button.reactivate_bot", function (e) {
|
||||||
var email = $(e.currentTarget).data('email');
|
var user_id = $(e.currentTarget).attr('data-user-id');
|
||||||
|
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/users/' + encodeURIComponent(email) + "/reactivate",
|
url: '/json/users/' + encodeURIComponent(user_id) + "/reactivate",
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
$('#bot_delete_error').text(JSON.parse(xhr.responseText).msg).show();
|
$('#bot_delete_error').text(JSON.parse(xhr.responseText).msg).show();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -300,10 +300,10 @@ exports.on_load_success = function (realm_people_data) {
|
|||||||
|
|
||||||
// Go up the tree until we find the user row, then grab the email element
|
// Go up the tree until we find the user row, then grab the email element
|
||||||
var row = $(e.target).closest(".user_row");
|
var row = $(e.target).closest(".user_row");
|
||||||
var email = get_email_for_user_row(row);
|
var user_id = row.attr("data-user-id");
|
||||||
|
|
||||||
channel.post({
|
channel.post({
|
||||||
url: '/json/users/' + encodeURIComponent(email) + "/reactivate",
|
url: '/json/users/' + encodeURIComponent(user_id) + "/reactivate",
|
||||||
error: function (xhr) {
|
error: function (xhr) {
|
||||||
ui_report.generic_row_button_error(xhr, $(e.target));
|
ui_report.generic_row_button_error(xhr, $(e.target));
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ class ActivateTest(ZulipTestCase):
|
|||||||
user = self.example_user('hamlet')
|
user = self.example_user('hamlet')
|
||||||
self.assertFalse(user.is_active)
|
self.assertFalse(user.is_active)
|
||||||
|
|
||||||
result = self.client_post('/json/users/hamlet@zulip.com/reactivate')
|
result = self.client_post('/json/users/{}/reactivate'.format(user.id))
|
||||||
self.assert_json_success(result)
|
self.assert_json_success(result)
|
||||||
user = self.example_user('hamlet')
|
user = self.example_user('hamlet')
|
||||||
self.assertTrue(user.is_active)
|
self.assertTrue(user.is_active)
|
||||||
@@ -379,7 +379,8 @@ class ActivateTest(ZulipTestCase):
|
|||||||
self.assert_json_error(result, 'Cannot deactivate the only organization administrator')
|
self.assert_json_error(result, 'Cannot deactivate the only organization administrator')
|
||||||
|
|
||||||
# Cannot reactivate a nonexistent user.
|
# Cannot reactivate a nonexistent user.
|
||||||
result = self.client_post('/json/users/nonexistent@zulip.com/reactivate')
|
invalid_user_id = 1000
|
||||||
|
result = self.client_post('/json/users/{}/reactivate'.format(invalid_user_id))
|
||||||
self.assert_json_error(result, 'No such user')
|
self.assert_json_error(result, 'No such user')
|
||||||
|
|
||||||
def test_api_with_insufficient_permissions(self) -> None:
|
def test_api_with_insufficient_permissions(self) -> None:
|
||||||
@@ -392,7 +393,7 @@ class ActivateTest(ZulipTestCase):
|
|||||||
self.assert_json_error(result, 'Insufficient permission')
|
self.assert_json_error(result, 'Insufficient permission')
|
||||||
|
|
||||||
# Cannot reactivate a user
|
# Cannot reactivate a user
|
||||||
result = self.client_post('/json/users/hamlet@zulip.com/reactivate')
|
result = self.client_post('/json/users/{}/reactivate'.format(self.example_user("hamlet").id))
|
||||||
self.assert_json_error(result, 'Insufficient permission')
|
self.assert_json_error(result, 'Insufficient permission')
|
||||||
|
|
||||||
def test_clear_scheduled_jobs(self) -> None:
|
def test_clear_scheduled_jobs(self) -> None:
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ def _deactivate_user_profile_backend(request: HttpRequest, user_profile: UserPro
|
|||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def reactivate_user_backend(request: HttpRequest, user_profile: UserProfile,
|
def reactivate_user_backend(request: HttpRequest, user_profile: UserProfile,
|
||||||
email: str) -> HttpResponse:
|
user_id: int) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
target = get_user(email, user_profile.realm)
|
target = get_user_profile_by_id_in_realm(user_id, user_profile.realm)
|
||||||
except UserProfile.DoesNotExist:
|
except UserProfile.DoesNotExist:
|
||||||
return json_error(_('No such user'))
|
return json_error(_('No such user'))
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ v1_api_and_json_patterns = [
|
|||||||
url(r'^users$', rest_dispatch,
|
url(r'^users$', rest_dispatch,
|
||||||
{'GET': 'zerver.views.users.get_members_backend',
|
{'GET': 'zerver.views.users.get_members_backend',
|
||||||
'POST': 'zerver.views.users.create_user_backend'}),
|
'POST': 'zerver.views.users.create_user_backend'}),
|
||||||
url(r'^users/(?!me/)(?P<email>[^/]*)/reactivate$', rest_dispatch,
|
url(r'^users/(?P<user_id>[0-9]+)/reactivate$', rest_dispatch,
|
||||||
{'POST': 'zerver.views.users.reactivate_user_backend'}),
|
{'POST': 'zerver.views.users.reactivate_user_backend'}),
|
||||||
url(r'^users/(?!me/)(?P<email>[^/]*)/presence$', rest_dispatch,
|
url(r'^users/(?!me/)(?P<email>[^/]*)/presence$', rest_dispatch,
|
||||||
{'GET': 'zerver.views.presence.get_presence_backend'}),
|
{'GET': 'zerver.views.presence.get_presence_backend'}),
|
||||||
|
|||||||
Reference in New Issue
Block a user