Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permissions manager #157

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Use of this source code is governed by MIT style
# license that can be found in the LICENSE file.

.PHONY: build run local down-local docker-clean logs-local migrate-version migrate-up migrate-down migrate-force
.PHONY: build run local down-local docker-clean logs-local

FILES := $(shell docker ps -aq)
DB_LOCAL := "postgres://postgres:postgres@localhost:5432/power-sso?sslmode=disable"

# - trimpath - will remove the filepathes from the reports, good to same money on network trafic,
# focus on bug reports, and find issues fast.
Expand Down Expand Up @@ -52,18 +51,6 @@ docker-clean:
logs-local:
@ docker logs -f $(FILES)

migrate-force:
@ migrate -source file://migrations -database $(DB_LOCAL) force 1

migrate-version:
migrate -source file://migrations -database $(DB_LOCAL) version

migrate-up:
migrate -source file://migrations -database $(DB_LOCAL) up

migrate-down:
migrate -source file://migrations -database $(DB_LOCAL) down

lint:
golangci-lint run ./...

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package auth
package authentication

import (
"context"

"github.com/google/uuid"
database "github.com/isaqueveras/powersso/database/postgres"
domain "github.com/isaqueveras/powersso/domain/auth"
infra "github.com/isaqueveras/powersso/infrastructure/persistencie/auth"
domain "github.com/isaqueveras/powersso/domain/authentication"
infra "github.com/isaqueveras/powersso/infrastructure/persistencie/authentication"
"github.com/isaqueveras/powersso/oops"
"github.com/isaqueveras/powersso/tokens"
"github.com/isaqueveras/powersso/utils"
Expand Down
13 changes: 13 additions & 0 deletions application/authorization/box/business.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package box

import (
"context"

"github.com/google/uuid"
)

// GetMyBox ...
func GetMyBox(ctx context.Context, uid *uuid.UUID) (res *MyBoxesRes, err error) {
res = new(MyBoxesRes)
return
}
14 changes: 14 additions & 0 deletions application/authorization/box/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package box

// MyBoxesRes ...
type MyBoxesRes struct {
Boxes []*Box `json:"boxes,omitempty"`
}

// Box ...
type Box struct {
Id *string `json:"id,omitempty"`
Name *string `json:"name" binding:"required,min=3,max=30"`
Desc *string `json:"desc,omitempty"`
CreatedByID *string `json:"created_by_id,omitempty"`
}
39 changes: 39 additions & 0 deletions application/authorization/organization/business.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2024 Isaque Veras
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package organization

import (
"context"

db "github.com/isaqueveras/powersso/database/postgres"
domain "github.com/isaqueveras/powersso/domain/authorization/organization"
infra "github.com/isaqueveras/powersso/infrastructure/persistencie/authorization/organization"
"github.com/isaqueveras/powersso/oops"
)

// Create is the business logic for creating a new room
func Create(ctx context.Context, in *Organization) (err error) {
var tx *db.Transaction
if tx, err = db.NewTransaction(ctx, false); err != nil {
return oops.Err(err)
}
defer tx.Rollback()

repo := infra.New(ctx, tx)
if err = repo.Create(&domain.Organization{
Name: in.Name,
Desc: in.Description,
URL: in.Url,
CreatedByID: in.CreatedByID,
}); err != nil {
return oops.Err(err)
}

if err = tx.Commit(); err != nil {
return oops.Err(err)
}

return nil
}
16 changes: 16 additions & 0 deletions application/authorization/organization/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 Isaque Veras
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package organization

import "github.com/google/uuid"

// Organization models the data to create a organization
type Organization struct {
ID *uuid.UUID `json:"-"`
Name *string `json:"name" binding:"required,min=3,max=20"`
Description *string `json:"description"`
Url *string `json:"url" binding:"required,max=200"`
CreatedByID *uuid.UUID `json:"-"`
}
51 changes: 51 additions & 0 deletions application/authorization/permission/business.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package permission

import (
"context"

"github.com/google/uuid"
"github.com/isaqueveras/powersso/database/postgres"
domain "github.com/isaqueveras/powersso/domain/authorization/permission"
"github.com/isaqueveras/powersso/infrastructure/persistencie/authorization/permission"
"github.com/isaqueveras/powersso/oops"
)

// Create ...
func Create(ctx context.Context, in *Permission) error {
tx, err := postgres.NewTransaction(ctx, false)
if err != nil {
return oops.Err(err)
}
defer tx.Rollback()

repo := permission.NewRepository(ctx, tx)
if err := repo.Create(&domain.Permission{
Name: in.Name,
Credential: in.Credential,
CreatedByID: in.CreatedByID,
}); err != nil {
return oops.Err(err)
}

if err = tx.Commit(); err != nil {
return oops.Err(err)
}

return nil
}

// Get ...
func Get(ctx context.Context, userID, organizationID *uuid.UUID) (permissions []*string, err error) {
tx, err := postgres.NewTransaction(ctx, true)
if err != nil {
return nil, oops.Err(err)
}
defer tx.Rollback()

repo := permission.NewRepository(ctx, tx)
if permissions, err = repo.Get(userID, organizationID); err != nil {
return nil, oops.Err(err)
}

return permissions, nil
}
21 changes: 21 additions & 0 deletions application/authorization/permission/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package permission

import (
"time"

"github.com/google/uuid"
)

// PermissionsRes models ...
type PermissionsRes struct {
OrganizationID *uuid.UUID `json:"organization_id"`
Permission *[]string `json:"permission"`
DateCache *time.Time `json:"date_cache,omitempty"`
}

// Permission ...
type Permission struct {
Name *string `json:"name"`
Credential *string `json:"credential"`
CreatedByID *uuid.UUID `json:"-"`
}
40 changes: 0 additions & 40 deletions application/project/business.go

This file was deleted.

49 changes: 0 additions & 49 deletions application/project/model.go

This file was deleted.

2 changes: 1 addition & 1 deletion delivery/grpc/auth/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions delivery/grpc/auth/auth_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions delivery/grpc/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package auth
import (
"context"

app "github.com/isaqueveras/powersso/application/auth"
domain "github.com/isaqueveras/powersso/domain/auth"
app "github.com/isaqueveras/powersso/application/authentication"
domain "github.com/isaqueveras/powersso/domain/authentication"
"github.com/isaqueveras/powersso/oops"
"github.com/isaqueveras/powersso/utils"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package auth
package authentication

import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/google/uuid"
app "github.com/isaqueveras/powersso/application/auth"
domain "github.com/isaqueveras/powersso/domain/auth"
app "github.com/isaqueveras/powersso/application/authentication"
domain "github.com/isaqueveras/powersso/domain/authentication"
"github.com/isaqueveras/powersso/i18n"
"github.com/isaqueveras/powersso/middleware"
"github.com/isaqueveras/powersso/oops"
Expand Down Expand Up @@ -82,13 +82,7 @@ func changePassword(ctx *gin.Context) {

// @Router /v1/auth/logout [DELETE]
func logout(ctx *gin.Context) {
sessionID, err := uuid.Parse(middleware.GetSession(ctx).SessionID)
if err != nil {
oops.Handling(ctx, err)
return
}

if err := app.Logout(ctx, utils.Pointer(sessionID)); err != nil {
if err := app.Logout(ctx, utils.Pointer(middleware.GetSession(ctx).SessionID)); err != nil {
oops.Handling(ctx, err)
return
}
Expand Down
Loading
Loading