feat: groups add deletion
This commit is contained in:
@@ -3,6 +3,7 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -49,3 +50,27 @@ func (gc *GroupController) AddGroupHandler(c *gin.Context) {
|
||||
|
||||
gc.GroupView(c)
|
||||
}
|
||||
|
||||
func (gc *GroupController) GroupHandler(c *gin.Context) {
|
||||
action := c.PostForm("action")
|
||||
idStr := c.Param("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
|
||||
if action == "delete" {
|
||||
err := services.Groups.Delete(c, int32(id))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
c.HTML(http.StatusBadRequest, "accessauths.html", gin.H{"error": err})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
gc.GroupView(c)
|
||||
}
|
||||
|
||||
9
main.go
9
main.go
@@ -14,9 +14,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
userController controllers.UserController = controllers.UserController{}
|
||||
groupController controllers.GroupController = controllers.GroupController{}
|
||||
authValidator middlewares.AuthValidator = middlewares.AuthValidator{}
|
||||
userController controllers.UserController = controllers.UserController{}
|
||||
groupController controllers.GroupController = controllers.GroupController{}
|
||||
accessAuthController controllers.AccessAuthController = controllers.AccessAuthController{}
|
||||
authValidator middlewares.AuthValidator = middlewares.AuthValidator{}
|
||||
)
|
||||
|
||||
func LoadEnvVariables() {
|
||||
@@ -57,7 +58,7 @@ func main() {
|
||||
|
||||
viewRoutes.GET("/groups", authValidator.RequireAdmin, groupController.GroupView)
|
||||
viewRoutes.POST("/groups", authValidator.RequireAdmin, groupController.AddGroupHandler)
|
||||
//viewRoutes.POST("/groups/:id", authValidator.RequireAdmin, groupController.GroupHandler)
|
||||
viewRoutes.POST("/groups/:id", authValidator.RequireAdmin, groupController.GroupHandler)
|
||||
|
||||
//write middleware that redirects to homescreen on register/login/reset for logged in users
|
||||
//viewRoutes.GET("/login", userController.LoginView)
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-2 mt-4 flex flex-wrap gap-2 w-full">
|
||||
<button type="submit" name="action" value="update" class="bg-blue-500 hover:bg-blue-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Update</button>
|
||||
<button type="submit" name="action" value="delete" class="bg-red-500 hover:bg-red-700 text-white text-sm/6 font-bold py-2 px-4 rounded">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
{{ if .isAdmin }}
|
||||
<div class="absolute inset-y-0 right-0 flex items-center pr-2 sm:static sm:inset-auto sm:ml-6 sm:pr-0 px-4 sm:px-8">
|
||||
<a href="/accessauth" class="rounded-md bg-gray-900 m-2 px-3 py-2 text-sm font-medium text-gray-300
|
||||
<a href="/access" class="rounded-md bg-gray-900 m-2 px-3 py-2 text-sm font-medium text-gray-300
|
||||
hover:bg-gray-700 hover:text-white">Manage Access Authorizations</a>
|
||||
<a href="/groups" class="rounded-md bg-gray-900 m-2 px-3 py-2 text-sm font-medium text-gray-300
|
||||
hover:bg-gray-700 hover:text-white">Manage Groups</a>
|
||||
|
||||
Reference in New Issue
Block a user