Skip to content

Commit

Permalink
Hide delete build button if not logged in as corresponding user
Browse files Browse the repository at this point in the history
  • Loading branch information
Pansysk75 committed Dec 31, 2023
1 parent 9ab5c07 commit d69711d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions web-app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ router.get('/user/:username', async (req, res) => {

const backendUrl = "http://64.226.122.251:81/"

// Get id from url
let username = req.params.username;

// Fetch user from backend
Expand All @@ -65,7 +64,7 @@ router.get('/user/:username', async (req, res) => {
console.log(error);
});

if (userData.error) {
if(userData == undefined || userData.error != undefined) {
res.send("User not found");
return;
}
Expand Down
1 change: 1 addition & 0 deletions web-app/src/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {config} from './config.js';

function deleteBuild(buildId) {
// Send a DELETE request to the backend API
// This is completely unsafe bc this is client-side code and anyone can send a DELETE request to the API
const url = `${config.backendUrl}/build/${buildId}`;
return fetch(url, {method: 'DELETE'})
.then(response => {
Expand Down
4 changes: 3 additions & 1 deletion web-app/views/user.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
<% for (let i = 0; i < user.builds_created.length; i++) { %>
<li class="build-created">
<a href="/build/<%= user.builds_created[i].Build_id %>"><%= user.builds_created[i].name %></a>
<button class="delete-build" value="<%= user.builds_created[i].Build_id %>">X</button>
<% if (session.Username == user.Username || session.Username == "admin" ) { %>
<button class="delete-build" value="<%= user.builds_created[i].Build_id %>">X</button>
<% } %>
</li>
<% } %>
</ul>
Expand Down

0 comments on commit d69711d

Please sign in to comment.