Some checks failed
go: build dev binaries / cleanup (push) Successful in 4s
Codespell / Check for spelling errors (push) Failing after 3s
docker: build dev containers / build-rust-binaries (amd64, x86_64-unknown-linux-musl) (push) Failing after 3s
docker: build dev containers / build-dev-containers (push) Has been skipped
docker: build dev containers / build-rust-binaries (arm64, true, aarch64-unknown-linux-musl) (push) Failing after 3s
End to End / FUSE Mount (push) Failing after 2s
EC Integration Tests / EC Integration Tests (push) Failing after 30s
FUSE DLM Integration Tests / FUSE DLM Integration Tests (push) Failing after 3s
FUSE Volume Server Failover Tests / FUSE Volume Server Failover (push) Failing after 3s
FUSE Integration Tests / FUSE Integration Testing (push) Failing after 2s
FUSE P2P Peer Chunk Sharing Integration Tests / FUSE P2P Peer Chunk Sharing (push) Failing after 3s
go: build binary / Go Vet (push) Failing after 2s
go: build binary / Go Vet 32-bit (push) Failing after 3s
go: build binary / Build (push) Failing after 4s
go: build binary / Build cross-platform (freebsd/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/amd64) (push) Failing after 3s
go: build binary / Build cross-platform (darwin/arm64) (push) Failing after 3s
go: build binary / Build cross-platform (windows/arm64) (push) Failing after 3s
go: build binary / Test (push) Failing after 2s
go: build binary / Test 32-bit (push) Failing after 3s
helm: lint and test charts / lint-test (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (11) (push) Failing after 3s
Java Client Integration Tests / Java Integration Tests (17) (push) Failing after 3s
go: build dev binaries / build_dev_linux_windows (amd64, linux) (push) Failing after 2s
go: build dev binaries / build_dev_linux_windows (amd64, windows) (push) Failing after 3s
go: build dev binaries / build_dev_darwin (amd64, darwin) (push) Has been skipped
go: build dev binaries / build_dev_darwin (arm64, darwin) (push) Has been skipped
Java Client Unit Tests / Java Unit Tests (11) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (17) (push) Failing after 2s
Java Client Unit Tests / Java Unit Tests (21) (push) Failing after 3s
Java Client Unit Tests / Java Unit Tests (8) (push) Failing after 3s
Kafka Quick Test (Load Test with Schema Registry) / Kafka Client Load Test (Quick) (push) Failing after 3s
Kafka Gateway Tests / Kafka Unit Tests (unit-tests-1) (push) Failing after 11s
Kafka Gateway Tests / Kafka Integration Tests (Critical) (integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka End-to-End Tests (with SMQ) (e2e-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Consumer Group Tests (Highly Isolated) (consumer-group-1) (push) Failing after 2s
Kafka Gateway Tests / Kafka Client Compatibility (with SMQ) (client-compat-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka SMQ Integration Tests (Full Stack) (smq-integration-1) (push) Failing after 3s
Kafka Gateway Tests / Kafka Protocol Tests (Isolated) (protocol-1) (push) Failing after 3s
KMS Tests / KMS Provider Integration Tests (push) Failing after 2s
KMS Tests / S3 KMS End-to-End Tests (push) Failing after 3s
Master Cold Start Tests / Master Cold Start Tests (push) Failing after 4s
Metadata Subscribe Integration Tests / Metadata Subscribe Integration Tests (push) Failing after 3s
Multi-Master Tests / Multi-Master Failover Tests (push) Failing after 3s
Performance / CPU and Heap Profile (push) Failing after 2s
Performance / S3 Read/Write Benchmark (rust volume) (push) Failing after 3s
pjdfstest POSIX Compliance / pjdfstest (push) Failing after 2s
Plugin Worker Integration Tests / Plugin Worker: erasure_coding (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: vacuum (push) Failing after 3s
Rust Volume Server Tests / Rust Integration Tests (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 1) (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 1) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 2) (push) Failing after 3s
Rust Volume Server Tests / Go Tests with Rust Volume (grpc - Shard 3) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Distributed Tests (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Performance Tests (push) Failing after 3s
Performance / Throughput Benchmark (go volume) (push) Failing after 3s
Performance / Throughput Benchmark (rust volume) (push) Failing after 2s
Performance / S3 Read/Write Benchmark (go volume) (push) Failing after 3s
Plugin Worker Integration Tests / Plugin Worker: volume_balance (push) Failing after 3s
PostgreSQL Gateway Tests / PostgreSQL Basic Tests (push) Failing after 3s
Rust Volume Server Tests / Rust Unit Tests (push) Failing after 2s
Rust Volume Server Tests / Go Tests with Rust Volume (http - Shard 3) (push) Failing after 3s
Rust Plugin Worker Tests / Rust Plugin Worker Build and Unit Tests (push) Failing after 3s
rust: build dev volume server binaries / cleanup (push) Successful in 3s
S3 ETag and ACL Tests / S3 ETag + ACL Integration Tests (push) Failing after 3s
S3 IAM Integration Tests / IAM Unit Tests (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (advanced) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (basic) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (group) (push) Failing after 3s
S3 IAM Integration Tests / S3 IAM Integration Tests (policy-enforcement) (push) Failing after 2s
S3 IAM Integration Tests / S3 IAM Integration Tests (sts) (push) Failing after 4s
S3 Keycloak Integration Tests / S3 Keycloak Integration Tests (push) Failing after 3s
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.11) (push) Failing after 3s
S3 PyArrow Parquet Tests / Go Unit Tests (Implicit Directory) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.12) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-amd64, x86_64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-darwin (darwin-arm64, aarch64-apple-darwin) (push) Has been cancelled
rust: build dev volume server binaries / build-rust-volume-dev-linux (linux-amd64, x86_64-unknown-linux-gnu) (push) Has been cancelled
S3 PyArrow Parquet Tests / PyArrow Parquet Tests (Python 3.9) (push) Has been cancelled
S3 Proxy Signature Tests / S3 Proxy Signature Verification Tests (push) Has been cancelled
S3 SDK V2 Route Disambiguation Tests / S3 SDK V2 Routing Tests (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (quick) (push) Has been cancelled
S3 SSE Tests / S3 SSE Compatibility Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Metadata Persistence Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Copy Operations Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Multipart Upload Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Performance Test (push) Has been cancelled
S3 SSE Tests / S3 Volume Encryption Test (push) Has been cancelled
S3 SSE Tests / S3 SSE Integration Tests (comprehensive) (push) Has been cancelled
Spark Integration Tests / Spark Integration Tests (push) Failing after 2s
Telemetry Integration Tests / telemetry-integration-test (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 1) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 1) (push) Failing after 3s
Ceph S3 tests / Basic S3 tests (KV store) (push) Has been cancelled
Ceph S3 tests / S3 Versioning & Object Lock tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Unit Tests (push) Failing after 3s
Ceph S3 tests / S3 CORS tests (push) Has been cancelled
Ceph S3 tests / SeaweedFS Custom S3 Copy tests (push) Has been cancelled
Ceph S3 tests / Basic S3 tests (SQL store) (push) Has been cancelled
test s3 over https using aws-cli / awscli-tests (push) Has been cancelled
TLS Rotation Integration Tests / TLS Rotation Integration Tests (push) Has been cancelled
Vacuum Integration Tests / Vacuum Integration Tests (push) Has been cancelled
S3 Policy Integration Tests / S3 Policy Variables Integration Tests (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (advanced-policy) (push) Failing after 3s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (basic-policy) (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Enforcement Integration Tests (contextual-policy) (push) Failing after 4s
S3 Policy Integration Tests / Trusted Proxy Detection Tests (push) Failing after 2s
S3 Policy Integration Tests / S3 Policy Shell Integration Tests (push) Failing after 3s
Samba on FUSE Integration / samba-integration (push) Failing after 2s
SFTP Integration Tests / SFTP Integration Testing (push) Failing after 3s
terraform: validate and test modules / fmt, validate, plan-level tests (push) Failing after 3s
terraform: validate and test modules / local cluster smoke test (real weed) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 3) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (grpc - Shard 2) (push) Failing after 3s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 2) (push) Failing after 2s
Volume Server Integration Tests / Volume Server Integration Tests (http - Shard 3) (push) Failing after 5s
mount: windows conformance / WinFsp conformance (push) Has been cancelled
mount: windows / Mount on Windows (push) Has been cancelled
443 lines
22 KiB
Plaintext
443 lines
22 KiB
Plaintext
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
|
)
|
|
|
|
templ Groups(data dash.GroupsPageData) {
|
|
<div class="container-fluid">
|
|
<!-- Page Header -->
|
|
<div class="d-sm-flex align-items-center justify-content-between mb-4">
|
|
<div>
|
|
<h1 class="h3 mb-0 text-gray-800">
|
|
<i class="fas fa-users-cog me-2"></i>Groups
|
|
</h1>
|
|
<p class="mb-0 text-muted">Manage IAM groups for organizing users and policies</p>
|
|
</div>
|
|
<div class="d-flex gap-2">
|
|
<button type="button" class="btn btn-primary"
|
|
data-bs-toggle="modal"
|
|
data-bs-target="#createGroupModal">
|
|
<i class="fas fa-plus me-1"></i>Create Group
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Summary Cards -->
|
|
<div class="row mb-4">
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-primary shadow h-100 py-2">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
|
|
Total Groups
|
|
</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
|
{fmt.Sprintf("%d", data.TotalGroups)}
|
|
</div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="fas fa-users-cog fa-2x text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-xl-3 col-md-6 mb-4">
|
|
<div class="card border-left-success shadow h-100 py-2">
|
|
<div class="card-body">
|
|
<div class="row no-gutters align-items-center">
|
|
<div class="col mr-2">
|
|
<div class="text-xs font-weight-bold text-success text-uppercase mb-1">
|
|
Active Groups
|
|
</div>
|
|
<div class="h5 mb-0 font-weight-bold text-gray-800">
|
|
{fmt.Sprintf("%d", data.ActiveGroups)}
|
|
</div>
|
|
</div>
|
|
<div class="col-auto">
|
|
<i class="fas fa-check-circle fa-2x text-gray-300"></i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Groups Table -->
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">Groups</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
if len(data.Groups) == 0 {
|
|
<div class="text-center py-5 text-muted">
|
|
<i class="fas fa-users-cog fa-3x mb-3"></i>
|
|
<p>No groups found. Create a group to get started.</p>
|
|
</div>
|
|
} else {
|
|
<div class="table-responsive">
|
|
<table class="table table-bordered table-hover" id="groupsTable" width="100%" cellspacing="0">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Members</th>
|
|
<th>Policies</th>
|
|
<th>Status</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
for _, group := range data.Groups {
|
|
<tr>
|
|
<td>
|
|
<strong>{group.Name}</strong>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-info">{fmt.Sprintf("%d", group.MemberCount)}</span>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-secondary">{fmt.Sprintf("%d", group.PolicyCount)}</span>
|
|
</td>
|
|
<td>
|
|
if group.Status == "enabled" {
|
|
<span class="badge bg-success">Enabled</span>
|
|
} else {
|
|
<span class="badge bg-danger">Disabled</span>
|
|
}
|
|
</td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-primary me-1"
|
|
data-group-name={group.Name}
|
|
data-action="view"
|
|
aria-label={"View group " + group.Name}
|
|
title={"View " + group.Name}>
|
|
<i class="fas fa-eye"></i>
|
|
</button>
|
|
<button class="btn btn-sm btn-outline-danger"
|
|
data-group-name={group.Name}
|
|
data-action="delete"
|
|
aria-label={"Delete group " + group.Name}
|
|
title={"Delete " + group.Name}>
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Create Group Modal -->
|
|
<div class="modal fade" id="createGroupModal" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Create Group</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="createGroupForm">
|
|
<div class="mb-3">
|
|
<label for="groupName" class="form-label">Group Name</label>
|
|
<input type="text" class="form-control" id="groupName" name="name" required
|
|
placeholder="Enter group name"/>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
<button type="button" class="btn btn-primary" onclick="createGroup()">Create</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- View Group Modal -->
|
|
<div class="modal fade" id="viewGroupModal" tabindex="-1">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="viewGroupTitle">Group Details</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<ul class="nav nav-tabs" id="groupTabs" role="tablist">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" id="members-tab" data-bs-toggle="tab" href="#membersPane" role="tab">Members</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" id="policies-tab" data-bs-toggle="tab" href="#policiesPane" role="tab">Policies</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" id="settings-tab" data-bs-toggle="tab" href="#settingsPane" role="tab">Settings</a>
|
|
</li>
|
|
</ul>
|
|
<div class="tab-content mt-3" id="groupTabContent">
|
|
<!-- Members Tab -->
|
|
<div class="tab-pane fade show active" id="membersPane" role="tabpanel">
|
|
<div class="mb-3">
|
|
<div class="input-group">
|
|
<select class="form-select" id="addMemberSelect">
|
|
<option value="">Select user to add...</option>
|
|
for _, user := range data.AvailableUsers {
|
|
<option value={user}>{user}</option>
|
|
}
|
|
</select>
|
|
<button class="btn btn-outline-primary" type="button" onclick="addMemberToGroup()">
|
|
<i class="fas fa-plus"></i> Add
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div id="membersList"></div>
|
|
</div>
|
|
<!-- Policies Tab -->
|
|
<div class="tab-pane fade" id="policiesPane" role="tabpanel">
|
|
<div class="mb-3">
|
|
<div class="input-group">
|
|
<select class="form-select" id="attachPolicySelect">
|
|
<option value="">Select policy to attach...</option>
|
|
for _, policy := range data.AvailablePolicies {
|
|
<option value={policy}>{policy}</option>
|
|
}
|
|
</select>
|
|
<button class="btn btn-outline-primary" type="button" onclick="attachPolicyToGroup()">
|
|
<i class="fas fa-plus"></i> Attach
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div id="policiesList"></div>
|
|
</div>
|
|
<!-- Settings Tab -->
|
|
<div class="tab-pane fade" id="settingsPane" role="tabpanel">
|
|
<div class="form-check form-switch mb-3">
|
|
<input class="form-check-input" type="checkbox" id="groupEnabledSwitch" checked
|
|
onchange="toggleGroupStatus()"/>
|
|
<label class="form-check-label" for="groupEnabledSwitch">Group Enabled</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Groups page JavaScript
|
|
let currentGroupName = '';
|
|
|
|
async function createGroup() {
|
|
const name = document.getElementById('groupName').value.trim();
|
|
if (!name) {
|
|
showAlert('Group name is required', 'error');
|
|
return;
|
|
}
|
|
try {
|
|
const response = await fetch(basePath('/api/groups'), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ name: name })
|
|
});
|
|
if (response.ok) {
|
|
showAlert('Group created successfully', 'success');
|
|
setTimeout(() => window.location.reload(), 1000);
|
|
} else {
|
|
const error = await response.json().catch(() => ({}));
|
|
showAlert('Failed to create group: ' + (error.error || 'Unknown error'), 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert('Failed to create group: ' + error.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function viewGroup(name) {
|
|
currentGroupName = name;
|
|
document.getElementById('viewGroupTitle').textContent = 'Group: ' + name;
|
|
await refreshGroupDetails(name);
|
|
new bootstrap.Modal(document.getElementById('viewGroupModal')).show();
|
|
}
|
|
|
|
async function refreshGroupDetails(requestedName) {
|
|
try {
|
|
const response = await fetch(basePath('/api/groups/' + encodeURIComponent(requestedName)));
|
|
if (!response.ok) throw new Error('Failed to fetch group');
|
|
if (requestedName !== currentGroupName) return; // stale response
|
|
const group = await response.json();
|
|
|
|
// Render members using DOM APIs to prevent XSS
|
|
const membersList = document.getElementById('membersList');
|
|
membersList.innerHTML = '';
|
|
const membersTable = document.createElement('table');
|
|
membersTable.className = 'table table-sm';
|
|
const membersTbody = document.createElement('tbody');
|
|
if (group.members && group.members.length > 0) {
|
|
for (const member of group.members) {
|
|
const tr = membersTbody.insertRow();
|
|
const td1 = tr.insertCell();
|
|
td1.textContent = member;
|
|
const td2 = tr.insertCell();
|
|
const btn = document.createElement('button');
|
|
btn.className = 'btn btn-sm btn-outline-danger';
|
|
btn.onclick = () => removeMember(member);
|
|
btn.innerHTML = '<i class="fas fa-times"></i>';
|
|
td2.appendChild(btn);
|
|
}
|
|
} else {
|
|
const tr = membersTbody.insertRow();
|
|
const td = tr.insertCell();
|
|
td.className = 'text-muted';
|
|
td.textContent = 'No members';
|
|
}
|
|
membersTable.appendChild(membersTbody);
|
|
membersList.appendChild(membersTable);
|
|
|
|
// Render policies using DOM APIs to prevent XSS
|
|
const policiesList = document.getElementById('policiesList');
|
|
policiesList.innerHTML = '';
|
|
const policiesTable = document.createElement('table');
|
|
policiesTable.className = 'table table-sm';
|
|
const policiesTbody = document.createElement('tbody');
|
|
if (group.policy_names && group.policy_names.length > 0) {
|
|
for (const policy of group.policy_names) {
|
|
const tr = policiesTbody.insertRow();
|
|
const td1 = tr.insertCell();
|
|
td1.textContent = policy;
|
|
const td2 = tr.insertCell();
|
|
const btn = document.createElement('button');
|
|
btn.className = 'btn btn-sm btn-outline-danger';
|
|
btn.onclick = () => detachPolicy(policy);
|
|
btn.innerHTML = '<i class="fas fa-times"></i>';
|
|
td2.appendChild(btn);
|
|
}
|
|
} else {
|
|
const tr = policiesTbody.insertRow();
|
|
const td = tr.insertCell();
|
|
td.className = 'text-muted';
|
|
td.textContent = 'No policies attached';
|
|
}
|
|
policiesTable.appendChild(policiesTbody);
|
|
policiesList.appendChild(policiesTable);
|
|
|
|
// Update status toggle
|
|
document.getElementById('groupEnabledSwitch').checked = (group.status === 'enabled');
|
|
} catch (error) {
|
|
console.error('Error fetching group details:', error);
|
|
}
|
|
}
|
|
|
|
async function addMemberToGroup() {
|
|
const username = document.getElementById('addMemberSelect').value;
|
|
if (!username) return;
|
|
try {
|
|
const response = await fetch(basePath('/api/groups/' + encodeURIComponent(currentGroupName) + '/members'), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ username: username })
|
|
});
|
|
if (response.ok) {
|
|
await refreshGroupDetails(currentGroupName);
|
|
showAlert('Member added', 'success');
|
|
} else {
|
|
const error = await response.json().catch(() => ({}));
|
|
showAlert('Failed to add member: ' + (error.error || 'Unknown error'), 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert('Failed to add member: ' + error.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function removeMember(username) {
|
|
try {
|
|
const response = await fetch(basePath('/api/groups/' + encodeURIComponent(currentGroupName) + '/members/' + encodeURIComponent(username)), {
|
|
method: 'DELETE'
|
|
});
|
|
if (response.ok) {
|
|
await refreshGroupDetails(currentGroupName);
|
|
showAlert('Member removed', 'success');
|
|
} else {
|
|
const error = await response.json().catch(() => ({}));
|
|
showAlert('Failed to remove member: ' + (error.error || 'Unknown error'), 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert('Failed to remove member: ' + error.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function attachPolicyToGroup() {
|
|
const policyName = document.getElementById('attachPolicySelect').value;
|
|
if (!policyName) return;
|
|
try {
|
|
const response = await fetch(basePath('/api/groups/' + encodeURIComponent(currentGroupName) + '/policies'), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ policy_name: policyName })
|
|
});
|
|
if (response.ok) {
|
|
await refreshGroupDetails(currentGroupName);
|
|
showAlert('Policy attached', 'success');
|
|
} else {
|
|
const error = await response.json().catch(() => ({}));
|
|
showAlert('Failed to attach policy: ' + (error.error || 'Unknown error'), 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert('Failed to attach policy: ' + error.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function detachPolicy(policyName) {
|
|
try {
|
|
const response = await fetch(basePath('/api/groups/' + encodeURIComponent(currentGroupName) + '/policies/' + encodeURIComponent(policyName)), {
|
|
method: 'DELETE'
|
|
});
|
|
if (response.ok) {
|
|
await refreshGroupDetails(currentGroupName);
|
|
showAlert('Policy detached', 'success');
|
|
} else {
|
|
const error = await response.json().catch(() => ({}));
|
|
showAlert('Failed to detach policy: ' + (error.error || 'Unknown error'), 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert('Failed to detach policy: ' + error.message, 'error');
|
|
}
|
|
}
|
|
|
|
async function toggleGroupStatus() {
|
|
const enabled = document.getElementById('groupEnabledSwitch').checked;
|
|
try {
|
|
const response = await fetch(basePath('/api/groups/' + encodeURIComponent(currentGroupName) + '/status'), {
|
|
method: 'PUT',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ enabled: enabled })
|
|
});
|
|
if (response.ok) {
|
|
showAlert('Group status updated', 'success');
|
|
} else {
|
|
const error = await response.json().catch(() => ({}));
|
|
showAlert('Failed to update status: ' + (error.error || 'Unknown error'), 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert('Failed to update status: ' + error.message, 'error');
|
|
}
|
|
}
|
|
|
|
// Event delegation for group action buttons
|
|
document.addEventListener('click', function(e) {
|
|
const btn = e.target.closest('[data-action]');
|
|
if (!btn) return;
|
|
const name = btn.dataset.groupName;
|
|
if (!name) return;
|
|
if (btn.dataset.action === 'view') viewGroup(name);
|
|
else if (btn.dataset.action === 'delete') deleteGroup(name);
|
|
});
|
|
</script>
|
|
}
|