mirror of https://github.com/jumpserver/jumpserver
user list groups bulk update
parent
15dcc760b4
commit
74cdd2d0f3
|
@ -156,8 +156,9 @@ class User(AbstractUser):
|
|||
|
||||
super(User, self).save(*args, **kwargs)
|
||||
# Add the current user to the default group.
|
||||
group = UserGroup.initial()
|
||||
self.groups.add(group)
|
||||
if not self.groups.count():
|
||||
group = UserGroup.initial()
|
||||
self.groups.add(group)
|
||||
|
||||
@property
|
||||
def private_token(self):
|
||||
|
|
|
@ -73,6 +73,7 @@ class UserPKUpdateSerializer(serializers.ModelSerializer):
|
|||
class UserBulkUpdateSerializer(BulkSerializerMixin, serializers.ModelSerializer):
|
||||
group_display = serializers.SerializerMethodField()
|
||||
active_display = serializers.SerializerMethodField()
|
||||
groups = serializers.PrimaryKeyRelatedField(many=True, queryset=UserGroup.objects.all())
|
||||
|
||||
class Meta(object):
|
||||
model = User
|
||||
|
|
|
@ -80,7 +80,8 @@ $(document).ready(function(){
|
|||
{targets: 0, orderable: false,
|
||||
createdCell: function(td) {
|
||||
$(td).html('<div class="checkbox checkbox-success"><input type="checkbox" class="ipt_check"><label></label></div>');
|
||||
}},
|
||||
}
|
||||
},
|
||||
{className: 'text-center', targets: [0, 1, 2, 3, 4, 5, 6, 7]},
|
||||
{targets: 7,
|
||||
createdCell: function (td, cellData, rowData) {
|
||||
|
@ -247,7 +248,30 @@ $(document).ready(function(){
|
|||
if (json_data.groups != undefined) {
|
||||
body.groups = json_data.groups;
|
||||
}
|
||||
console.log(body)
|
||||
if (typeof body.groups === 'string') {
|
||||
body.groups = [parseInt(body.groups)]
|
||||
} else if(typeof body.groups === 'array') {
|
||||
new_groups = body.groups.map(Number);
|
||||
body.groups = new_groups;
|
||||
}
|
||||
var $data_table = $('#user_list_table').DataTable()
|
||||
var post_list = [];
|
||||
$data_table.rows({selected: true}).every(function(){
|
||||
var content = Object.assign({id: this.data().id}, body);
|
||||
post_list.push(content);
|
||||
});
|
||||
if (post_list === []) {
|
||||
return false;
|
||||
};
|
||||
var the_url = "{% url 'users:user-bulk-update-api' %}";
|
||||
var success = function() {
|
||||
var msg = "{% trans 'The selected users has been updated successfully.' %}";
|
||||
swal("{% trans 'User Updated' %}", msg, "success");
|
||||
$('#user_list_table').DataTable().ajax.reload();
|
||||
jumpserver.checked = false;
|
||||
}
|
||||
APIUpdateAttr({url: the_url, method: 'PATCH', body: JSON.stringify(post_list), success: success});
|
||||
$('#user_bulk_update_modal').modal('hide');
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue