Compare commits

..

No commits in common. "7e3c9e0767c3542fcdca665e1d70f150f4f7d64d" and "06fe13ee2edecd7b9d9a54f433804c212c9487fe" have entirely different histories.

4 changed files with 16 additions and 97 deletions

View File

@ -157,59 +157,3 @@
(api-output `(("status" . "success") (api-output `(("status" . "success")
("message" . ,(format nil "Password reset for user: ~a" username))))))) ("message" . ,(format nil "Password reset for user: ~a" username)))))))
(define-api asteroid/user/activate (user-id active) ()
"API endpoint for setting the active state of an user account"
(format t "Activation of user: #~a set to ~a~%" user-id active)
(require-role :admin)
(with-error-handling
(let ((user (when user-id
(find-user-by-id user-id)))
(active (if (stringp active)
(parse-integer active)
active)))
(unless user
(error 'not-found-error :message "User not found"))
;; Change user active state
(let ((result (if (= 0 active)
(deactivate-user user-id)
(activate-user user-id))))
(if result
(api-output `(("status" . "success")
("message" . ,(format nil "User '~a' ~a."
(dm:field user "username")
(if (= 0 active)
"deactivated"
"activated")))))
(api-output `(("status" . "error")
("message" . ,(format nil "Could not ~a user '~a'."
(if (= 0 active)
"deactivated"
"activated")
(dm:field user "username"))))))))))
(define-api asteroid/user/role (user-id role) ()
"API endpoint for setting the access role of an user account"
(format t "Role of user: #~a set to ~a~%" user-id role)
(require-role :admin)
(with-error-handling
(let ((user (when user-id
(find-user-by-id user-id)))
(user-role (intern (string-upcase role) :keyword)))
(unless user
(error 'not-found-error :message "User not found"))
;; Change user role
(let ((result (update-user-role user-id user-role)))
(if result
(api-output `(("status" . "success")
("message" . ,(format nil "User '~a' is now a ~a."
(dm:field user "username")
role))))
(api-output `(("status" . "error")
("message" . ,(format nil "Could not set user '~a' as ~a."
(dm:field user "username")
role)))))))))

View File

@ -307,7 +307,7 @@
:text-align center) :text-align center)
((:and audio |::-webkit-media-controls-panel|) ((:and audio |::-webkit-media-controls-panel|)
:background-color "#1a2332") :background-color "#1a1a1a")
;; ((:and audio (:or |::-webkit-media-controls-mute-button| ;; ((:and audio (:or |::-webkit-media-controls-mute-button|
;; |::-webkit-media-controls-play-button| ;; |::-webkit-media-controls-play-button|

View File

@ -90,23 +90,20 @@ function hideUsersTable() {
async function updateUserRole(userId, newRole) { async function updateUserRole(userId, newRole) {
try { try {
const formData = new FormData(); const formData = new FormData();
formData.append('user-id', userId);
formData.append('role', newRole); formData.append('role', newRole);
const response = await fetch('/api/asteroid/user/role', { const response = await fetch(`/api/asteroid/users/${userId}/role`, {
method: 'POST', method: 'POST',
body: formData body: formData
}); });
const result = await response.json(); const result = await response.json();
// Handle Radiance API data wrapping
const data = result.data || result;
if (data.status === 'success') { if (result.status === 'success') {
loadUserStats(); loadUserStats();
alert(data.message); alert('User role updated successfully');
} else { } else {
alert('Error updating user role: ' + data.message); alert('Error updating user role: ' + result.message);
} }
} catch (error) { } catch (error) {
console.error('Error updating user role:', error); console.error('Error updating user role:', error);
@ -120,25 +117,18 @@ async function deactivateUser(userId) {
} }
try { try {
const formData = new FormData(); const response = await fetch(`/api/asteroid/users/${userId}/deactivate`, {
formData.append('user-id', userId); method: 'POST'
formData.append('active', 0);
const response = await fetch('/api/asteroid/user/activate', {
method: 'POST',
body: formData
}); });
const result = await response.json(); const result = await response.json();
// Handle Radiance API data wrapping
const data = result.data || result;
if (data.status === 'success') { if (result.status === 'success') {
loadUsers(); loadUsers();
loadUserStats(); loadUserStats();
alert(data.message); alert('User deactivated successfully');
} else { } else {
alert('Error deactivating user: ' + data.message); alert('Error deactivating user: ' + result.message);
} }
} catch (error) { } catch (error) {
console.error('Error deactivating user:', error); console.error('Error deactivating user:', error);
@ -147,31 +137,19 @@ async function deactivateUser(userId) {
} }
async function activateUser(userId) { async function activateUser(userId) {
if (!confirm('Are you sure you want to activate this user?')) {
return;
}
try { try {
const response = await fetch(`/api/asteroid/users/${userId}/activate`, {
const formData = new FormData(); method: 'POST'
formData.append('user-id', userId);
formData.append('active', 1);
const response = await fetch('/api/asteroid/user/activate', {
method: 'POST',
body: formData
}); });
const result = await response.json(); const result = await response.json();
// Handle Radiance API data wrapping
const data = result.data || result;
if (data.status === 'success') { if (result.status === 'success') {
loadUsers(); loadUsers();
loadUserStats(); loadUserStats();
alert(data.message); alert('User activated successfully');
} else { } else {
alert('Error activating user: ' + data.message); alert('Error activating user: ' + result.message);
} }
} catch (error) { } catch (error) {
console.error('Error activating user:', error); console.error('Error activating user:', error);

View File

@ -40,10 +40,7 @@
(defun find-user-by-id (user-id) (defun find-user-by-id (user-id)
"Find a user by ID" "Find a user by ID"
(format t "Looking for user with ID: ~a (type: ~a)~%" user-id (type-of user-id)) (format t "Looking for user with ID: ~a (type: ~a)~%" user-id (type-of user-id))
(let* ((user-id (if (stringp user-id) (let ((user (dm:get-one "USERS" (db:query (:= '_id user-id)))))
(parse-integer user-id)
user-id))
(user (dm:get-one "USERS" (db:query (:= '_id user-id)))))
(when user (when user
(format t "Found user '~a' with id #~a~%" (format t "Found user '~a' with id #~a~%"
(dm:field user "username") (dm:field user "username")