admin interface works
All checks were successful
gitea.arg.rip/vassago/pipeline/head This commit looks good

This commit is contained in:
adam 2025-04-24 12:54:30 -04:00
parent e85a61607e
commit 631347aed8
3 changed files with 258 additions and 18 deletions

View File

@ -123,4 +123,91 @@ public class UACController: ControllerBase
Rememberer.RememberUAC(uacFromDb); Rememberer.RememberUAC(uacFromDb);
return Ok(uacFromDb); return Ok(uacFromDb);
} }
[HttpPatch]
[Route("UnlinkUser")]
[Produces("application/json")]
public IActionResult UnlinkUser([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkUser req)
{
var uac_guid = req.uac_guid;
var user_guid = req.user_guid;
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
if (uacFromDb == null)
{
_logger.LogError($"attempt to unlink uac for uac {uac_guid}, not found");
return NotFound();
}
var userFromDb = Rememberer.SearchUser(c => c.Id == user_guid);
if (userFromDb == null)
{
_logger.LogError($"attempt to unlink user for user {user_guid}, not found");
return NotFound();
}
uacFromDb.Users ??= [];
if (!uacFromDb.Users.Contains(userFromDb))
{
return BadRequest("user not linked");
}
uacFromDb.Users.Remove(userFromDb);
Rememberer.RememberUAC(uacFromDb);
return Ok(uacFromDb);
}
[HttpPatch]
[Route("UnlinkAccount")]
[Produces("application/json")]
public IActionResult UnlinkAccount([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkAccount req)
{
var uac_guid = req.uac_guid;
var account_guid = req.account_guid;
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
if (uacFromDb == null)
{
_logger.LogError($"attempt to unlink uac for uac {uac_guid}, not found");
return NotFound();
}
var accountFromDb = Rememberer.SearchAccount(a => a.Id == account_guid);
if (accountFromDb == null)
{
_logger.LogError($"attempt to unlink account for user {account_guid}, not found");
return NotFound();
}
uacFromDb.AccountInChannels ??= [];
if (!uacFromDb.AccountInChannels.Contains(accountFromDb))
{
return BadRequest("account not linked");
}
uacFromDb.AccountInChannels.Remove(accountFromDb);
Rememberer.RememberUAC(uacFromDb);
return Ok(uacFromDb);
}
[HttpPatch]
[Route("UnlinkChannel")]
[Produces("application/json")]
public IActionResult UnlinkChannel([FromBody] extraSpecialObjectReadGlorifiedTupleFor_LinkChannel req)
{
var uac_guid = req.uac_guid;
var channel_guid = req.channel_guid;
var uacFromDb = Rememberer.SearchUAC(uac => uac.Id == uac_guid);
if (uacFromDb == null)
{
_logger.LogError($"attempt to unlink channal for uac {uac_guid}, not found");
return NotFound();
}
var channelFromDb = Rememberer.SearchChannel(c => c.Id == channel_guid);
if (channelFromDb == null)
{
_logger.LogError($"attempt to unlink user for user {channel_guid}, not found");
return NotFound();
}
uacFromDb.Users ??= [];
if (!uacFromDb.Channels.Contains(channelFromDb))
{
return BadRequest("user not linked");
}
uacFromDb.Channels.Remove(channelFromDb);
Rememberer.RememberUAC(uacFromDb);
return Ok(uacFromDb);
}
} }

View File

@ -38,7 +38,7 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title">Insert GUID</h5> <h5 class="modal-title">Insert GUID</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="btn btn-close" data-dismiss="add-modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
@ -54,12 +54,39 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="modalsubmit" type="button" class="btn btn-primary">Save changes</button> <button id="modalsubmit" type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-secondary" data-dismiss="add-modal">Close</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div id="remove-modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Confirm</h5>
<button type="button" class="btn-close" data-dismiss="remove-modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>
are you sure you wnat to unlink
<input id="removeModalText" enabled="false" type="text" />
</p>
<p>
to be clear; this is going to "unlink", not like.. delete.
</p>
</div>
<div class="modal-footer">
<button id="modalsubmit" type="button" class="btn btn-danger">unlink</button>
<button type="button" class="btn btn-secondary" data-dismiss="remove-modal">Close</button>
</div>
</div>
</div>
</div>
@section Scripts{ @section Scripts{
<script type="text/javascript"> <script type="text/javascript">
function addChannel(){ function addChannel(){
@ -69,7 +96,7 @@
} }
function addChannelSubmit(){ function addChannelSubmit(){
let guid = document.querySelector("#add-modal #addmodaltext").value; let guid = document.querySelector("#add-modal #addmodaltext").value;
linkUAC_Channel(guid); linkUAC_Channel(guid, () => { window.location.reload(); });
$("#add-modal").modal("hide"); $("#add-modal").modal("hide");
console.log(guid); console.log(guid);
} }
@ -80,7 +107,7 @@
} }
function addUserSubmit(){ function addUserSubmit(){
let guid = document.querySelector("#add-modal #addmodaltext").value; let guid = document.querySelector("#add-modal #addmodaltext").value;
linkUAC_User(guid); linkUAC_User(guid, () => {window.location.reload(); });
$("#add-modal").modal("hide"); $("#add-modal").modal("hide");
console.log(guid); console.log(guid);
} }
@ -91,20 +118,53 @@
} }
function addAccountSubmit(){ function addAccountSubmit(){
let guid = document.querySelector("#add-modal #addmodaltext").value; let guid = document.querySelector("#add-modal #addmodaltext").value;
linkUAC_Account(guid); linkUAC_Account(guid, () => { window.location.reload(); });
$("#add-modal").modal("hide"); $("#add-modal").modal("hide");
console.log(guid); console.log(guid);
} }
function removeUser(guid){
document.querySelector("#remove-modal #removeModalText").value = guid;
let modalbutton = document.querySelector("#remove-modal button#modalsubmit");
modalbutton.onclick = removeUserSubmit;
$("#remove-modal").modal("show");
}
function removeUserSubmit(){
let guid = document.querySelector("#remove-modal #removeModalText").value;
unlinkUAC_User(guid, () => { window.location.reload(); });
$("#remove-modal").modal("hide");
}
function removeChannel(guid){
document.querySelector("#remove-modal #removeModalText").value = guid;
let modalbutton = document.querySelector("#remove-modal button#modalsubmit");
modalbutton.onclick = removeChannelSubmit;
$("#remove-modal").modal("show");
}
function removeChannelSubmit(){
let guid = document.querySelector("#remove-modal #removeModalText").value;
unlinkUAC_Channel(guid, () => { window.location.reload(); });
$("#remove-modal").modal("hide");
}
function removeAccount(guid){
document.querySelector("#remove-modal #removeModalText").value = guid;
let modalbutton = document.querySelector("#remove-modal button#modalsubmit");
modalbutton.onclick = removeAccountSubmit;
$("#remove-modal").modal("show");
}
function removeAccountSubmit(){
let guid = document.querySelector("#remove-modal #removeModalText").value;
unlinkUAC_Account(guid , () => { window.location.reload(); });
$("#remove-modal").modal("hide");
}
function channelsTree() { function channelsTree() {
@{ @{
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.Append("[{text: \"Channels\", \"expanded\":true, nodes: ["); sb.Append("[{text: \"Channels\", \"expanded\":true, nodes: [");
sb.Append($"{{text: \"<button onclick=\\\"addChannel()\\\">add channel<button>\"}}"); sb.Append($"{{text: \"<button type=\\\"button\\\" class=\\\"btn btn-primary\\\" onclick=\\\"addChannel()\\\">add channel</button>\"}}");
foreach (var acc in Model.Channels?.OrderBy(a => a.DisplayName)) foreach (var acc in Model.Channels?.OrderBy(a => a.DisplayName))
{ {
sb.Append(','); sb.Append(',');
sb.Append($"{{text: \"<a href=\\\"/Channels/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn\\\" onclick=\\\"removeUser('{acc.Id}')\\\">remove (todo)</button>\"}}"); sb.Append($"{{text: \"<a href=\\\"/Channels/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn btn-danger\\\" onclick=\\\"removeChannel('{acc.Id}')\\\">remove</button>\"}}");
} }
sb.Append("]}]"); sb.Append("]}]");
} }
@ -116,11 +176,11 @@
sb = new StringBuilder(); sb = new StringBuilder();
sb.Append("[{text: \"Users\", \"expanded\":true, nodes: ["); sb.Append("[{text: \"Users\", \"expanded\":true, nodes: [");
sb.Append($"{{text: \"<button onclick=\\\"addUser()\\\">add user</button>\"}}"); sb.Append($"{{text: \"<button type=\\\"button\\\" class=\\\"btn btn-primary\\\" onclick=\\\"addUser()\\\">add user</button>\"}}");
foreach (var acc in Model.Users?.OrderBy(a => a.DisplayName)) foreach (var acc in Model.Users?.OrderBy(a => a.DisplayName))
{ {
sb.Append(','); sb.Append(',');
sb.Append($"{{text: \"<a href=\\\"/Users/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn\\\" onclick=\\\"removeUser('{acc.Id}')\\\">remove (todo)</button>\"}}"); sb.Append($"{{text: \"<a href=\\\"/Users/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn btn-danger\\\" onclick=\\\"removeUser('{acc.Id}')\\\">remove</button>\"}}");
} }
sb.Append("]}]"); sb.Append("]}]");
} }
@ -132,11 +192,11 @@
sb = new StringBuilder(); sb = new StringBuilder();
sb.Append("[{text: \"Accounts\", \"expanded\":true, nodes: ["); sb.Append("[{text: \"Accounts\", \"expanded\":true, nodes: [");
sb.Append($"{{text: \"<button onclick=\\\"addAccount()\\\">add account</button>\"}}"); sb.Append($"{{text: \"<button type=\\\"button\\\" class=\\\"btn btn-primary\\\" onclick=\\\"addAccount()\\\">add account</button>\"}}");
foreach (var acc in Model.AccountInChannels?.OrderBy(a => a.DisplayName)) foreach (var acc in Model.AccountInChannels?.OrderBy(a => a.DisplayName))
{ {
sb.Append(','); sb.Append(',');
sb.Append($"{{text: \"<a href=\\\"/Accounts/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn\\\" onclick=\\\"removeAccounts('{acc.Id}')\\\">remove (todo)</button>\"}}"); sb.Append($"{{text: \"<a href=\\\"/Accounts/Details/{acc.Id}\\\">{acc.DisplayName}</a> - <button type=\\\"button\\\" class=\\\"btn btn-danger\\\" onclick=\\\"removeAccount('{acc.Id}')\\\">remove</button>\"}}");
} }
sb.Append("]}]"); sb.Append("]}]");
} }
@ -147,5 +207,8 @@
$('#usersTree').bstreeview({ data: usersTree() }); $('#usersTree').bstreeview({ data: usersTree() });
$('#accountsTree').bstreeview({ data: accountsTree() }); $('#accountsTree').bstreeview({ data: accountsTree() });
var components = window.location.pathname.split('/');
var uacId = components[3];
</script> </script>
} }

View File

@ -21,7 +21,6 @@ function patchModel(model, deprecated_apiUrl)
var type=components[1]; var type=components[1];
// var id=components[3]; // var id=components[3];
console.log("dexter impression: I am now ready to post the following content:");
console.log(JSON.stringify(model)); console.log(JSON.stringify(model));
fetch(apiUrl + type + '/', { fetch(apiUrl + type + '/', {
method: 'PATCH', method: 'PATCH',
@ -53,6 +52,7 @@ function deleteModel(model, deprecated_apiUrl)
// console.log("wtf are you doing? " + components[2] + " is something other than Details"); // console.log("wtf are you doing? " + components[2] + " is something other than Details");
// } // }
var type=components[1]; var type=components[1];
let result = null;
// var id=components[3]; // var id=components[3];
fetch(apiUrl + type + '/', { fetch(apiUrl + type + '/', {
method: 'DELETE', method: 'DELETE',
@ -70,13 +70,15 @@ function deleteModel(model, deprecated_apiUrl)
.then(returnedSuccessdata => { .then(returnedSuccessdata => {
// perhaps a success callback // perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata); console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);
}); });
} }
function linkUAC_Channel(channel_guid) function linkUAC_Channel(channel_guid, callback)
{ {
var components = window.location.pathname.split('/'); var components = window.location.pathname.split('/');
var id=components[3]; var id=components[3];
let model={"uac_guid": id, let model={"uac_guid": id,
@ -97,12 +99,13 @@ function linkUAC_Channel(channel_guid)
.then(returnedSuccessdata => { .then(returnedSuccessdata => {
// perhaps a success callback // perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata); console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);
}); });
} }
function linkUAC_User(user_guid) function linkUAC_User(user_guid, callback)
{ {
var components = window.location.pathname.split('/'); var components = window.location.pathname.split('/');
var id=components[3]; var id=components[3];
@ -124,13 +127,15 @@ function linkUAC_User(user_guid)
.then(returnedSuccessdata => { .then(returnedSuccessdata => {
// perhaps a success callback // perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata); console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);
}); });
} }
function linkUAC_Account(account_guid) function linkUAC_Account(account_guid, callback)
{ {
var reuslt = null;
var components = window.location.pathname.split('/'); var components = window.location.pathname.split('/');
var id=components[3]; var id=components[3];
let model={"uac_guid": id, let model={"uac_guid": id,
@ -151,6 +156,91 @@ function linkUAC_Account(account_guid)
.then(returnedSuccessdata => { .then(returnedSuccessdata => {
// perhaps a success callback // perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata); console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
})
.catch(error => {
console.error('Error:', error);
});
}
function unlinkUAC_User(user_guid, callback)
{
var components = window.location.pathname.split('/');
var id=components[3];
let model={"uac_guid": id,
"user_guid": user_guid};
fetch(apiUrl + "UAC/UnlinkUser/", {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(model),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not "ok". which is not ok.');
}
return response.json();
})
.then(returnedSuccessdata => {
// perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
})
.catch(error => {
console.error('Error:', error);
});
}
function unlinkUAC_Account(account_guid, callback)
{
var components = window.location.pathname.split('/');
var id=components[3];
let model={"uac_guid": id,
"account_guid": account_guid};
fetch(apiUrl + "UAC/UnlinkAccount/", {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(model),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not "ok". which is not ok.');
}
return response.json();
})
.then(returnedSuccessdata => {
// perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
})
.catch(error => {
console.error('Error:', error);
});
}
function unlinkUAC_Channel(user_guid, callback)
{
var components = window.location.pathname.split('/');
var id=components[3];
let model={"uac_guid": id,
"channel_guid": user_guid};
fetch(apiUrl + "UAC/UnlinkChannel/", {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(model),
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not "ok". which is not ok.');
}
return response.json();
})
.then(returnedSuccessdata => {
// perhaps a success callback
console.log('returnedSuccessdata:', returnedSuccessdata);
if(callback !== null) { callback(); }
}) })
.catch(error => { .catch(error => {
console.error('Error:', error); console.error('Error:', error);