Skip to content

Commit

Permalink
feat: allow super admins to update users profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Sep 23, 2024
1 parent 4a7cb6b commit 960566d
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<p align="center">
<img alt="Lynx Logo" src="/assets/img/logo.png?v=0.11.17" width="250" />
<img alt="Lynx Logo" src="/assets/img/logo.png?v=0.12.0" width="250" />
<h3 align="center">Lynx</h3>
<p align="center">A Fast, Secure and Reliable Terraform Backend, Set up in Minutes.</p>
<p align="center">
<a href="https://github.com/Clivern/Lynx/actions/workflows/ci.yml">
<img src="https://github.com/Clivern/Lynx/actions/workflows/server_ci.yml/badge.svg"/>
</a>
<a href="https://github.com/Clivern/Lynx/releases">
<img src="https://img.shields.io/badge/Version-0.11.17-1abc9c.svg">
<img src="https://img.shields.io/badge/Version-0.12.0-1abc9c.svg">
</a>
<a href="https://hub.docker.com/r/clivern/lynx/tags">
<img src="https://img.shields.io/badge/Docker-0.11.17-1abc9c.svg">
<img src="https://img.shields.io/badge/Docker-0.12.0-1abc9c.svg">
</a>
<a href="https://github.com/Clivern/terraform-provider-lynx">
<img src="https://img.shields.io/badge/Terraform-Provider-yellow.svg">
Expand Down
2 changes: 1 addition & 1 deletion api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
license:
name: MIT License
url: https://github.com/Clivern/Lynx/blob/main/LICENSE
version: 0.11.17
version: 0.12.0
externalDocs:
description: Find out more about lynx
url: https://github.com/Clivern/Lynx
Expand Down
6 changes: 3 additions & 3 deletions docker-compose-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'

services:
app1:
image: clivern/lynx:0.11.17
image: clivern/lynx:0.12.0
environment:
APP_NAME: Lynx
APP_PORT: 4001
Expand All @@ -27,7 +27,7 @@ services:
- db

app2:
image: clivern/lynx:0.11.17
image: clivern/lynx:0.12.0
environment:
APP_NAME: Lynx
APP_PORT: 4002
Expand All @@ -52,7 +52,7 @@ services:
- db

app3:
image: clivern/lynx:0.11.17
image: clivern/lynx:0.12.0
environment:
APP_NAME: Lynx
APP_PORT: 4003
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'

services:
app:
image: clivern/lynx:0.11.17
image: clivern/lynx:0.12.0
environment:
APP_NAME: Lynx
APP_PORT: 4000
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.8'

services:
app:
image: clivern/lynx:0.11.17
image: clivern/lynx:0.12.0
environment:
APP_NAME: Lynx
APP_PORT: 4000
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ hero:
icon: edit

download_link:
label: Latest Release v0.11.17
url: https://github.com/Clivern/Lynx/releases/tag/0.11.17
label: Latest Release v0.12.0
url: https://github.com/Clivern/Lynx/releases/tag/0.12.0

features:
rows:
Expand Down
2 changes: 1 addition & 1 deletion lib/lynx_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ defmodule LynxWeb.Router do

defp add_server_header(conn, _opts) do
conn
|> put_resp_header("x-server-version", "lynx/0.11.17")
|> put_resp_header("x-server-version", "lynx/0.12.0")
end

# Enables LiveDashboard only for development
Expand Down
65 changes: 63 additions & 2 deletions lib/lynx_web/templates/page/teams.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
new_team: '<%= gettext "Team created successfully!" %>',
delete_team_message: '<%= gettext "Team deleted successfully!" %>',
delete_team_alert: '<%= gettext "You are trying to delete a team! are you sure?" %>',
delete_team_endpoint: '<%= Routes.team_path(@conn, :delete, "UUID") %>'
delete_team_endpoint: '<%= Routes.team_path(@conn, :delete, "UUID") %>',
update_team_endpoint: '<%= Routes.team_path(@conn, :update, "UUID") %>'
}
</script>

Expand Down Expand Up @@ -294,7 +295,8 @@
<td style="text-align: center">${formatDatetime(team.createdAt)}</td>
<td>
<!--
<button @click="editTeamAction(team.id)" class="btn btn-dashed btn-sm text-black-100 border-black-100 hp-hover-text-color-black-80 hp-hover-border-color-black-80"><%= gettext "Edit" %></button>-->
<button @click="editTeamAction(team.id)" class="btn btn-dashed btn-sm text-black-100 border-black-100 hp-hover-text-color-black-80 hp-hover-border-color-black-80" data-bs-toggle="modal" data-bs-target="#edit_team_modal"><%= gettext "Edit" %></button>
-->
<button @click="deleteTeamAction(team.id)" class="btn btn-dashed btn-sm text-danger border-danger hp-hover-text-color-danger-2 hp-hover-border-color-danger-2"><%= gettext "Delete" %></button>
</td>
</tr>
Expand Down Expand Up @@ -391,7 +393,66 @@
</div>
</div>
</div>
<!--
<div class="modal fade" id="edit_team_modal" tabindex="-1" aria-labelledby="editTeamLabel" aria-hidden="true" data-action={Routes.user_path(@conn, :list)}>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header py-16 px-24">
<h5 class="modal-title" id="editTeamLabel"><%= gettext "Edit Team" %></h5>
<button type="button" class="btn-close hp-bg-none d-flex align-items-center justify-content-center" data-bs-dismiss="modal" aria-label="Close">
<i class="ri-close-line hp-text-color-dark-0 lh-1" style="font-size: 24px;"></i>
</button>
</div>
<div class="divider m-0"></div>
<form id="update_team_form" action={Routes.team_path(@conn, :update, "UUID")} method="post" v-on:submit.prevent="updateTeamAction">
<input type="hidden" value="" name="uuid">
<div class="modal-body">
<div class="row gx-8">
<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Name" %></label>
<input type="text" v-model="teamName" @input="slugifyTeamName" class="form-control" name="name" required="required" minlength="2" maxlength="60">
</div>
</div>
<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Slug" %></label>
<input type="text" v-model="teamSlug" class="form-control" name="slug" required="required" minlength="2" maxlength="60">
</div>
</div>
<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Description" %></label>
<textarea name="description" class="form-control" required="required" minlength="2" maxlength="250"></textarea>
</div>
</div>
<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Members" %></label>
<select class="form-select" multiple name="members" required="required">
<template v-for="user in users">
<option :value="user.id">${user.name} (${user.email})</option>
</template>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer pt-0 px-24 pb-24">
<div class="divider"></div>
<button type="submit" class="m-0 btn btn-primary w-100" :disabled="isInProgress"><%= gettext "Submit" %></button>
</div>
</form>
</div>
</div>
</div>
-->
</div>

<footer class="w-100 py-18 px-16 py-sm-24 px-sm-32 hp-bg-color-black-20 hp-bg-color-dark-90">
Expand Down
65 changes: 62 additions & 3 deletions lib/lynx_web/templates/page/users.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
var _globals = {
new_user: '<%= gettext "User created successfully!" %>',
delete_user_message: '<%= gettext "User deleted successfully!" %>',
update_user_message: '<%= gettext "User updated successfully!" %>',
delete_user_alert: '<%= gettext "You are trying to delete a user! are you sure?" %>',
delete_user_endpoint: '<%= Routes.user_path(@conn, :delete, "UUID") %>'
delete_user_endpoint: '<%= Routes.user_path(@conn, :delete, "UUID") %>',
update_user_endpoint: '<%= Routes.user_path(@conn, :update, "UUID") %>'
}
</script>

Expand Down Expand Up @@ -293,8 +295,7 @@
<td style="text-align: center">${user.role}</td>
<td style="text-align: center">${formatDatetime(user.createdAt)}</td>
<td>
<!--
<button @click="editUserAction(user.id)" class="btn btn-dashed btn-sm text-black-100 border-black-100 hp-hover-text-color-black-80 hp-hover-border-color-black-80"><%= gettext "Edit" %></button>-->
<button @click="editUserAction(user.id)" class="btn btn-dashed btn-sm text-black-100 border-black-100 hp-hover-text-color-black-80 hp-hover-border-color-black-80" data-bs-toggle="modal" data-bs-target="#edit_user_modal"><%= gettext "Edit" %></button>
<button @click="deleteUserAction(user.id)" class="btn btn-dashed btn-sm text-danger border-danger hp-hover-text-color-danger-2 hp-hover-border-color-danger-2"><%= gettext "Delete" %></button>
</td>
</tr>
Expand Down Expand Up @@ -390,6 +391,64 @@
</div>
</div>

<div class="modal fade" id="edit_user_modal" tabindex="-1" aria-labelledby="editUserLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header py-16 px-24">
<h5 class="modal-title" id="editUserLabel"><%= gettext "Edit User" %></h5>
<button type="button" class="btn-close hp-bg-none d-flex align-items-center justify-content-center" data-bs-dismiss="modal" aria-label="Close">
<i class="ri-close-line hp-text-color-dark-0 lh-1" style="font-size: 24px;"></i>
</button>
</div>

<div class="divider m-0"></div>

<form id="update_user_form" action={Routes.user_path(@conn, :update, "UUID")} method="post" v-on:submit.prevent="updateUserAction">
<input type="hidden" value="" name="uuid">
<div class="modal-body">
<div class="row gx-8">
<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Nick Name" %></label>
<input type="text" class="form-control" name="name" required="required" minlength="2" maxlength="60">
</div>
</div>

<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Role" %></label>
<select class="form-select" name="role" required="required">
<option value="regular" selected><%= gettext "Regular" %></option>
<option value="super"><%= gettext "Super" %></option>
</select>
</div>
</div>

<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "Email" %></label>
<input type="email" class="form-control" name="email" required="required">
</div>
</div>

<div class="col-12">
<div class="mb-24">
<label class="form-label"><%= gettext "New Password" %></label>
<input type="password" class="form-control" name="password">
</div>
</div>
</div>
</div>

<div class="modal-footer pt-0 px-24 pb-24">
<div class="divider"></div>
<button type="submit" class="m-0 btn btn-primary w-100" :disabled="isInProgress"><%= gettext "Submit" %></button>
</div>
</form>
</div>
</div>
</div>

</div>

<footer class="w-100 py-18 px-16 py-sm-24 px-sm-32 hp-bg-color-black-20 hp-bg-color-dark-90">
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
defmodule Lynx.MixProject do
use Mix.Project

@version "0.11.17"
@version "0.12.0"

def get_version, do: @version

Expand Down
72 changes: 71 additions & 1 deletion priv/static/theme/app/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ lynx_app.teams_list = (Vue, axios, $) => {
methods: {
editTeamAction(id) {
console.log("Edit team with ID:", id);
//$('input[name="uuid"]').val(id);
//$('form#update_team_form').attr('action', function(i, val) {
// return val.replace('UUID', id);
//});
},

formatDatetime(datatime) {
Expand Down Expand Up @@ -520,7 +524,21 @@ lynx_app.users_list = (Vue, axios, $) => {
},
methods: {
editUserAction(id) {
console.log("Edit user with ID:", id);
$('input[name="uuid"]').val(id);
$('form#update_user_form').attr('action', function(i, val) {
return val.replace('UUID', id);
});
axios.get($("#update_user_form").attr("action"))
.then((response) => {
if (response.status >= 200) {
$('form#update_user_form input[name="name"]').val(response.data.name);
$('form#update_user_form select[name="role"]').val(response.data.role);
$('form#update_user_form input[name="email"]').val(response.data.email);
}
})
.catch((error) => {
show_notification(error.response.data.errorMessage);
});
},

formatDatetime(datatime) {
Expand Down Expand Up @@ -585,6 +603,50 @@ lynx_app.users_list = (Vue, axios, $) => {
});
}


lynx_app.edit_user_modal = (Vue, axios, $) => {

return new Vue({
delimiters: ['${', '}'],
el: '#edit_user_modal',
data() {
return {
isInProgress: false
}
},
methods: {
updateUserAction(event) {
event.preventDefault();
this.isInProgress = true;

let inputs = {};
let _self = $(event.target);
let _form = _self.closest("form");

_form.serializeArray().map((item, index) => {
inputs[item.name] = item.value;
});

axios.put(_form.attr('action'), inputs)
.then((response) => {
if (response.status >= 200) {
show_notification(_globals.update_user_message);

setTimeout(() => {
location.reload();
}, 2000);
}
})
.catch((error) => {
this.isInProgress = false;
// Show error
show_notification(error.response.data.errorMessage);
});
}
}
});
}

// Projects list
lynx_app.projects_list = (Vue, axios, $) => {

Expand Down Expand Up @@ -1249,4 +1311,12 @@ $(document).ready(() => {
$
);
}

if (document.getElementById("edit_user_modal")) {
lynx_app.edit_user_modal(
Vue,
axios,
$
);
}
});

0 comments on commit 960566d

Please sign in to comment.