Unverified Commit 16864ca3 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

[Update] 用户列表添加移除操作(在其他组织中) (#3513)

* [Update] 用户列表添加移除操作(在其他组织中)

* [Update] 用户列表添加移除操作(在其他组织中)2
parent c5785e17
......@@ -149,11 +149,7 @@ class CanUpdateDeleteUser(permissions.BasePermission):
return False
if obj.is_super_auditor:
return False
if obj.is_org_admin:
return False
if len(obj.audit_orgs) > 1:
return False
if len(obj.user_orgs) > 1:
if obj.can_admin_current_org:
return False
return True
......@@ -174,12 +170,6 @@ class CanUpdateDeleteUser(permissions.BasePermission):
return False
if obj.is_super_auditor:
return False
if obj.is_org_admin:
return False
if len(obj.audit_orgs) > 1:
return False
if len(obj.user_orgs) > 1:
return False
return True
def has_object_permission(self, request, view, obj):
......
This diff is collapsed.
......@@ -316,7 +316,7 @@ function requestApi(props) {
}
// Sweet Alert for Delete
function objectDelete(obj, name, url, redirectTo) {
function objectDelete(obj, name, url, redirectTo, title, success_message) {
function doDelete() {
var body = {};
var success = function () {
......@@ -335,14 +335,14 @@ function objectDelete(obj, name, url, redirectTo) {
url: url,
body: JSON.stringify(body),
method: 'DELETE',
success_message: gettext("Delete the success"),
success_message: success_message || gettext("Delete the success"),
success: success,
error: fail
});
}
swal({
title: gettext('Are you sure about deleting it?'),
title: title || gettext('Are you sure about deleting it?'),
text: " [" + name + "] ",
type: "warning",
showCancelButton: true,
......
......@@ -7,7 +7,7 @@
<script src="{% static "js/plugins/toastr/toastr.min.js" %}"></script>
<script src="{% static "js/inspinia.js" %}"></script>
<script type="text/javascript" src="{% url 'javascript-catalog' %}"></script>
<script src="{% static "js/jumpserver.js" %}?v=5"></script>
<script src="{% static "js/jumpserver.js" %}?v=6"></script>
<script src="{% static 'js/plugins/select2/select2.full.min.js' %}"></script>
<script src="{% static 'js/plugins/select2/i18n/zh-CN.js' %}"></script>
<script>
......
......@@ -67,6 +67,12 @@ class UserViewSet(CommonApiMixin, UserQuerysetMixin, BulkModelViewSet):
self.permission_classes = (IsSuperUser,)
return super().get_permissions()
def perform_destroy(self, instance):
if current_org.is_real():
instance.remove()
else:
return super().perform_destroy(instance)
def perform_bulk_destroy(self, objects):
for obj in objects:
self.check_object_permissions(self.request, obj)
......
......@@ -267,6 +267,16 @@ class RoleMixin:
access_key = app.create_access_key()
return app, access_key
def remove(self):
if not current_org.is_real():
return
if self.can_user_current_org:
current_org.users.remove(self)
if self.can_admin_current_org:
current_org.admins.remove(self)
if self.can_audit_current_org:
current_org.auditors.remove(self)
class TokenMixin:
CACHE_KEY_USER_RESET_PASSWORD_PREFIX = "_KEY_USER_RESET_PASSWORD_{}"
......
......@@ -47,7 +47,11 @@
<div id="actions" class="hide">
<div class="input-group">
<select class="form-control m-b" style="width: auto" id="slct_bulk_update">
{% if CURRENT_ORG == 'DEFAULT' %}
<option value="delete">{% trans 'Delete selected' %}</option>
{% else %}
<option value="remove">{% trans 'Remove selected' %}</option>
{% endif %}
<option value="update">{% trans 'Update selected' %}</option>
<option value="deactive">{% trans 'Deactive selected' %}</option>
<option value="active">{% trans 'Active selected' %}</option>
......@@ -107,16 +111,31 @@ function initTable() {
}
var del_btn = "";
var rm_btn = "";
if ("{{ CURRENT_ORG }}" === 'DEFAULT'){
if (rowData.can_delete === false){
del_btn = '<a class="btn btn-xs btn-danger m-l-xs" disabled>{% trans "Delete" %}</a>'
.replace('{{ DEFAULT_PK }}', cellData)
.replace('99991938', name);
} else {
del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-uid="{{ DEFAULT_PK }}" data-name="99991938">{% trans "Delete" %}</a>'
del_btn = '<a class="btn btn-xs btn-danger m-l-xs btn_user_delete" data-action="delete" data-uid="{{ DEFAULT_PK }}" data-name="99991938">{% trans "Delete" %}</a>'
.replace('{{ DEFAULT_PK }}', cellData)
.replace('99991938', name);
}
$(td).html(update_btn + del_btn)
}
else{
if (rowData.can_delete === false){
rm_btn = '<a class="btn btn-xs btn-warning m-l-xs" disabled>{% trans "Remove" %}</a>'
.replace('{{ DEFAULT_PK }}', cellData)
.replace('99991938', name);
} else {
rm_btn = '<a class="btn btn-xs btn-warning m-l-xs btn_user_delete" data-action="remove" data-uid="{{ DEFAULT_PK }}" data-name="99991938">{% trans "Remove" %}</a>'
.replace('{{ DEFAULT_PK }}', cellData)
.replace('99991938', name);
}
$(td).html(update_btn + rm_btn)
}
}}],
ajax_url: '{% url "api-users:user-list" %}',
columns: [
......@@ -245,10 +264,11 @@ $(document).ready(function(){
success: reloadPage
});
}
function doDelete() {
function doDelete(props) {
props = props || {};
swal({
title: "{% trans 'Are you sure?' %}",
text: "{% trans 'This will delete the selected users !!!' %}",
text: props.text || "{% trans 'This will delete the selected users !!!' %}",
type: "warning",
showCancelButton: true,
cancelButtonText: "{% trans 'Cancel' %}",
......@@ -258,10 +278,6 @@ $(document).ready(function(){
},function () {
function success(data) {
url = setUrlParam(the_url, 'spm', data.spm);
function success() {
var msg = "{% trans 'User Deleted.' %}";
swal("{% trans 'User Delete' %}", msg, "success");
}
function fail() {
var msg = "{% trans 'User Deleting failed.' %}";
swal("{% trans 'User Delete' %}", msg, "error");
......@@ -271,7 +287,7 @@ $(document).ready(function(){
method:'DELETE',
flash_message:true,
success:reloadPage,
error: fail
error: props.fail || fail
});
}
requestApi({
......@@ -284,6 +300,17 @@ $(document).ready(function(){
})
}
function doRemove(){
var props = {
text: "{% trans 'This will remove the selected users !!' %}",
fail: function fail(){
var msg = "{% trans 'User Removing failed.' %}";
swal("{% trans 'User Remove' %}", msg, "error");
}
};
doDelete(props);
}
function doUpdate() {
function fail(data) {
toastr.error(JSON.parse(data))
......@@ -308,6 +335,9 @@ $(document).ready(function(){
case 'delete':
doDelete();
break;
case 'remove':
doRemove();
break;
case 'update':
doUpdate();
break;
......@@ -321,8 +351,14 @@ $(document).ready(function(){
var $this = $(this);
var name = $this.data('name');
var uid = $this.data('uid');
var action = $this.data('action');
var title, success_message = null;
if (action === 'remove'){
title = "{% trans 'Are you sure about removing it?' %}";
success_message = "{% trans 'Remove the success' %}";
}
var the_url = '{% url "api-users:user-detail" pk=DEFAULT_PK %}'.replace("{{ DEFAULT_PK }}", uid);
objectDelete($this, name, the_url);
objectDelete($this, name, the_url, null, title, success_message);
}).on('click', '.expired', function () {
var msg = '{% trans "User is expired" %}';
toastr.error(msg)
......
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