Skip to content

Commit a5220d9

Browse files
authored
Merge pull request #3 from limanmys/feature/new-vault-system
Feature/new vault system
2 parents a29d9eb + 9eb96d6 commit a5220d9

File tree

9 files changed

+52
-49
lines changed

9 files changed

+52
-49
lines changed

app/handlers/extension.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ func ExtensionRunner(c *fiber.Ctx) error {
2727
return err
2828
}
2929

30-
if extension.Status == "0" {
31-
return logger.FiberError(fiber.StatusServiceUnavailable, "extension is unavailable")
32-
}
33-
3430
credentials := &models.Credentials{}
3531
if extension.RequireKey == "true" {
3632
credentials, err = liman.GetCredentials(

app/handlers/external.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ func ExternalAPI(c *fiber.Ctx) error {
3232
return logger.FiberError(fiber.StatusBadRequest, "extension not found")
3333
}
3434

35-
if extension.Status == "0" {
36-
return logger.FiberError(fiber.StatusServiceUnavailable, "extension is unavailable")
37-
}
38-
3935
credentials := &models.Credentials{}
4036
if extension.RequireKey == "true" {
4137
credentials, err = liman.GetCredentials(

app/handlers/file.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ func DownloadFile(c *fiber.Ctx) error {
112112
return err
113113
}
114114

115-
if extension.Status == "0" {
116-
return logger.FiberError(fiber.StatusServiceUnavailable, "extension is unavailable")
117-
}
118-
119115
credentials := &models.Credentials{}
120116
if extension.RequireKey == "true" {
121117
credentials, err = liman.GetCredentials(

app/handlers/job.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ func BackgroundJob(c *fiber.Ctx) error {
2323
return err
2424
}
2525

26-
if extension.Status == "0" {
27-
return logger.FiberError(fiber.StatusServiceUnavailable, "extension is unavailable")
28-
}
29-
3026
credentials := &models.Credentials{}
3127
if extension.RequireKey == "true" {
3228
credentials, err = liman.GetCredentials(

app/models/extension.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@ package models
22

33
// Extension Structure of the extension obj
44
type Extension struct {
5-
ID string `json:"id"`
6-
Name string `json:"name"`
7-
Version string `json:"version"`
8-
Icon string `json:"-"`
9-
Service string `json:"service"`
10-
CreatedAt string `json:"-"`
11-
UpdatedAt string `json:"-"`
12-
Order int `json:"-"`
13-
SslPorts string `json:"sslPorts" pg:"sslPorts"`
14-
Issuer string `json:"issuer"`
15-
Language string `json:"-"`
16-
Support string `json:"support"`
17-
Displays string `json:"displays"`
18-
Status string `json:"status"`
19-
RequireKey string `json:"require_key"`
5+
ID string `json:"id"`
6+
Name string `json:"name"`
7+
Version string `json:"version"`
8+
VersionCode string `json:"version_code"`
9+
Icon string `json:"-"`
10+
CreatedAt string `json:"-"`
11+
UpdatedAt string `json:"-"`
12+
SslPorts string `json:"sslPorts" pg:"sslPorts"`
13+
RequireKey string `json:"require_key"`
2014
}
2115

2216
func (Extension) TableName() string {

internal/liman/role_system.go

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package liman
22

33
import (
4+
"encoding/json"
45
"strings"
56

67
"github.com/gofiber/fiber/v2"
@@ -11,14 +12,14 @@ import (
1112
)
1213

1314
// GetPermissions Gets user and extensions permissons and variables
14-
func GetPermissions(user *models.User, extFilter string) ([]string, map[string]string, error) {
15+
func GetPermissions(user *models.User, extFilter string) ([]string, map[string]interface{}, error) {
1516
roles, err := getRoleMaps(user)
1617
if err != nil {
1718
return nil, nil, err
1819
}
1920

2021
permissions := []string{}
21-
variables := make(map[string]string)
22+
variables := make(map[string]interface{})
2223
for _, role := range roles {
2324
permission, variable, err := getPermissionsFromMorph(role, strings.ToLower(extFilter))
2425
if err != nil {
@@ -27,7 +28,7 @@ func GetPermissions(user *models.User, extFilter string) ([]string, map[string]s
2728

2829
permissions = append(permissions, permission...)
2930

30-
variables = helpers.MergeStringMaps(variables, variable)
31+
variables = helpers.MergeInterfaceMaps(variables, variable)
3132
}
3233

3334
if user.AuthType == "keycloak" {
@@ -63,7 +64,7 @@ func GetObjectPermissions(user *models.User) ([]string, error) {
6364
}
6465

6566
// getPermissionsFromMorph Searches db for morph relationships and returns permissions
66-
func getPermissionsFromMorph(morphID string, extFilter string) ([]string, map[string]string, error) {
67+
func getPermissionsFromMorph(morphID string, extFilter string) ([]string, map[string]interface{}, error) {
6768
permission := []*models.Permission{}
6869

6970
err := database.Connection().Find(&permission, "morph_id = ?", morphID).Error
@@ -72,7 +73,7 @@ func getPermissionsFromMorph(morphID string, extFilter string) ([]string, map[st
7273
}
7374

7475
funcPerms := []string{}
75-
varPerms := make(map[string]string)
76+
varPerms := make(map[string]interface{})
7677

7778
for _, item := range permission {
7879
if item.Type == "function" {
@@ -86,7 +87,32 @@ func getPermissionsFromMorph(morphID string, extFilter string) ([]string, map[st
8687
}
8788

8889
if item.Type == "variable" {
89-
varPerms[item.Key] = item.Value
90+
if item.Extra == "multiselect" || item.Extra == "array" {
91+
var value []interface{}
92+
json.Unmarshal([]byte(item.Value), &value)
93+
varPerms[item.Key] = value
94+
continue
95+
}
96+
97+
// Check if item is a json object
98+
if item.Extra == "json" {
99+
var value interface{}
100+
json.Unmarshal([]byte(item.Value), &value)
101+
varPerms[item.Key] = value
102+
continue
103+
}
104+
105+
if existing, ok := varPerms[item.Key]; ok {
106+
if existingSlice, ok := existing.([]string); ok {
107+
existingSlice = append(existingSlice, item.Value)
108+
varPerms[item.Key] = existingSlice
109+
} else {
110+
// If it's not a slice, convert it to a slice
111+
varPerms[item.Key] = []string{existing.(string), item.Value}
112+
}
113+
} else {
114+
varPerms[item.Key] = item.Value
115+
}
90116
}
91117
}
92118

internal/process_queue/create_report.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ func (c CreateReport) Process() error {
3333
c.Queue.UpdateError(err.Error())
3434
return err
3535
}
36-
// Check extension status
37-
if extension.Status == "0" {
38-
// Update job as failed
39-
c.Queue.UpdateError("extension is unavailable")
40-
return err
41-
}
4236

4337
// Get credentials
4438
credentials := &models.Credentials{}

pkg/cron_jobs/cron_jobs.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ func RegisterAndRun(cj models.CronJob) error {
3131
cj.UpdateAsFailed(err.Error())
3232
return
3333
}
34-
// Check extension status
35-
if extension.Status == "0" {
36-
// Update job as failed
37-
cj.UpdateAsFailed("extension is unavailable")
38-
return
39-
}
4034

4135
// Get credentials
4236
credentials := &models.Credentials{}

pkg/helpers/maps.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ func MergeStringMaps(ms ...map[string]string) map[string]string {
1010
}
1111
return res
1212
}
13+
14+
// This function x interface maps together
15+
func MergeInterfaceMaps(ms ...map[string]interface{}) map[string]interface{} {
16+
res := map[string]interface{}{}
17+
for _, m := range ms {
18+
for k, v := range m {
19+
res[k] = v
20+
}
21+
}
22+
return res
23+
}

0 commit comments

Comments
 (0)