-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
55 lines (47 loc) · 1.55 KB
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2007-2024 by Ubaldo Porcheddu <ubaldo@eja.it>
package db
import (
"fmt"
)
// TypeModulePath represents a node in the module hierarchy with its ID, name, and translated label.
type TypeModulePath struct {
Id int64
Name string
Label string
}
// ModulePath retrieves the path of module hierarchy from the specified module to its root for a given user.
func ModulePath(ownerId int64, moduleId int64) (result []TypeModulePath) {
id := moduleId
ejaPermissions := ModuleGetIdByName("ejaPermissions")
ejaUsers := ModuleGetIdByName("ejaUsers")
ejaGroups := ModuleGetIdByName("ejaGroups")
owners := NumbersToCsv(UserGroupList(ownerId))
for id != 0 {
row, _ := Row("SELECT ejaId, parentId, name FROM ejaModules WHERE ejaId=?", id)
result = append(result, TypeModulePath{
Id: Number(row["ejaId"]),
Name: row["name"],
Label: Translate(row["name"], ownerId),
})
id = 0
if len(row) > 0 {
query := fmt.Sprintf(`
SELECT ejaId FROM ejaLinks
WHERE
srcModuleId=?
AND srcFieldId IN (SELECT ejaId FROM ejaPermissions WHERE ejaModuleId=?)
AND ((dstFieldId=? AND dstModuleId=?) || (dstModuleId=? AND dstFieldId IN (%s)))
LIMIT 1
`, owners)
checkId, _ := Value(query, ejaPermissions, Number(row["ejaId"]), ownerId, ejaUsers, ejaGroups)
if (ownerId == 1 || Number(checkId) > 0) && Number(row["parentId"]) > 0 {
id = Number(row["parentId"])
}
}
}
for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
result[i], result[j] = result[j], result[i]
}
result = result[:len(result)-1]
return
}