Browse Source

admin UI: add anonymous user creation checkbox (#8773)

Add an "Anonymous" checkbox next to the username field in the Create User
modal. When checked, the username is set to "anonymous" and the credential
generation checkbox is disabled since anonymous users do not need keys.

The checkbox is only shown when no anonymous user exists yet. The
manage-access-keys button in the users table is hidden for the anonymous
user.
pull/8392/merge
Chris Lu 2 days ago
committed by GitHub
parent
commit
67a551fd62
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 9
      weed/admin/dash/admin_data.go
  2. 17
      weed/admin/handlers/user_handlers.go
  3. 42
      weed/admin/view/app/object_store_users.templ
  4. 57
      weed/admin/view/app/object_store_users_templ.go

9
weed/admin/dash/admin_data.go

@ -48,10 +48,11 @@ type ObjectStoreUser struct {
}
type ObjectStoreUsersData struct {
Username string `json:"username"`
Users []ObjectStoreUser `json:"users"`
TotalUsers int `json:"total_users"`
LastUpdated time.Time `json:"last_updated"`
Username string `json:"username"`
Users []ObjectStoreUser `json:"users"`
TotalUsers int `json:"total_users"`
HasAnonymousUser bool `json:"has_anonymous_user"`
LastUpdated time.Time `json:"last_updated"`
}
// User management request structures

17
weed/admin/handlers/user_handlers.go

@ -311,10 +311,19 @@ func (h *UserHandlers) getObjectStoreUsersData(r *http.Request) dash.ObjectStore
}
}
hasAnonymous := false
for _, u := range users {
if u.Username == "anonymous" {
hasAnonymous = true
break
}
}
return dash.ObjectStoreUsersData{
Username: username,
Users: users,
TotalUsers: len(users),
LastUpdated: time.Now(),
Username: username,
Users: users,
TotalUsers: len(users),
HasAnonymousUser: hasAnonymous,
LastUpdated: time.Now(),
}
}

42
weed/admin/view/app/object_store_users.templ

@ -141,10 +141,12 @@ templ ObjectStoreUsers(data dash.ObjectStoreUsersData) {
data-action="edit-user" data-username={ user.Username }>
<i class="fas fa-edit"></i>
</button>
<button type="button" class="btn btn-outline-secondary"
data-action="manage-access-keys" data-username={ user.Username }>
<i class="fas fa-key"></i>
</button>
if user.Username != "anonymous" {
<button type="button" class="btn btn-outline-secondary"
data-action="manage-access-keys" data-username={ user.Username }>
<i class="fas fa-key"></i>
</button>
}
<button type="button" class="btn btn-outline-danger"
data-action="delete-user" data-username={ user.Username }>
<i class="fas fa-trash"></i>
@ -197,7 +199,17 @@ templ ObjectStoreUsers(data dash.ObjectStoreUsersData) {
<form id="createUserForm">
<div class="mb-3">
<label for="username" class="form-label">Username *</label>
<input type="text" class="form-control" id="username" name="username" required>
if !data.HasAnonymousUser {
<div class="input-group">
<input type="text" class="form-control" id="username" name="username" required>
<div class="input-group-text">
<input class="form-check-input mt-0 me-1" type="checkbox" id="anonymousCheck" onchange="toggleAnonymousUser()">
<label class="form-check-label small" for="anonymousCheck">Anonymous</label>
</div>
</div>
} else {
<input type="text" class="form-control" id="username" name="username" required>
}
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
@ -669,6 +681,24 @@ templ ObjectStoreUsers(data dash.ObjectStoreUsersData) {
}
}
// Toggle anonymous user checkbox
function toggleAnonymousUser() {
const checkbox = document.getElementById('anonymousCheck');
const usernameInput = document.getElementById('username');
const generateKey = document.getElementById('generateKey');
if (checkbox.checked) {
usernameInput.value = 'anonymous';
usernameInput.readOnly = true;
generateKey.checked = false;
generateKey.disabled = true;
} else {
usernameInput.value = '';
usernameInput.readOnly = false;
generateKey.disabled = false;
generateKey.checked = true;
}
}
// Populate bucket selection dropdowns
function populateBucketSelections() {
const createSelect = document.getElementById('selectedBuckets');
@ -1055,6 +1085,8 @@ templ ObjectStoreUsers(data dash.ObjectStoreUsersData) {
const modal = bootstrap.Modal.getInstance(document.getElementById('createUserModal'));
modal.hide();
form.reset();
document.getElementById('username').readOnly = false;
document.getElementById('generateKey').disabled = false;
setTimeout(() => window.location.reload(), 1000);
} else {
const error = await response.json();

57
weed/admin/view/app/object_store_users_templ.go
File diff suppressed because it is too large
View File

Loading…
Cancel
Save