community profile and left menu implementation done, not quite working yet

This commit is contained in:
2025-10-16 23:05:34 -06:00
parent 681b30272d
commit 65c739dc57
17 changed files with 412 additions and 72 deletions
+31 -8
View File
@@ -165,16 +165,39 @@ func (c *Community) Membership(u *User) (bool, bool, uint16, error) {
* true if the user has the permission, false if not.
* Standard Go error status.
*/
func (c *Community) TestPermission(user *User, perm string) (bool, error) {
member, _, level, err := c.Membership(user)
if err != nil {
return false, err
func (c *Community) TestPermission(perm string, level uint16) bool {
switch perm {
case "Community.Read":
return level >= c.ReadLevel
case "Community.Write":
return level >= c.WriteLevel
case "Community.Create":
return level >= c.CreateLevel
case "Community.Delete":
return level >= c.DeleteLevel
case "Community.Join":
return level >= c.JoinLevel
default:
return AmTestPermission(perm, level)
}
effectiveLevel := user.BaseLevel
if member && level > effectiveLevel {
effectiveLevel = level
}
// PermissionLevel returns trhe permission level for a permission name.
func (c *Community) PermissionLevel(perm string) uint16 {
switch perm {
case "Community.Read":
return c.ReadLevel
case "Community.Write":
return c.WriteLevel
case "Community.Create":
return c.CreateLevel
case "Community.Delete":
return c.DeleteLevel
case "Community.Join":
return c.JoinLevel
default:
return AmPermissionLevel(perm)
}
return AmTestPermission(perm, effectiveLevel), nil
}
/* AmGetCommunity returns a reference to the specified community.
+2 -2
View File
@@ -22,8 +22,8 @@ import (
type ContactInfo struct {
Mutex sync.Mutex
ContactId int32 `db:"contactid"`
GivenName string `db:"given_name"`
FamilyName string `db:"family_name"`
GivenName *string `db:"given_name"`
FamilyName *string `db:"family_name"`
MiddleInit *string `db:"middle_init"`
Prefix *string `db:"prefix"`
Suffix *string `db:"suffix"`
+22 -1
View File
@@ -254,5 +254,26 @@ func AmRoleList(id string) RoleList {
* true if the permission test is satisfied, false if not.
*/
func AmTestPermission(id string, level uint16) bool {
return securityRoot.permsMap[id].level < level
return securityRoot.permsMap[id].level <= level
}
// AmPermissionLevel returns a level value for a permission.
func AmPermissionLevel(id string) uint16 {
return securityRoot.permsMap[id].level
}
/* AmCombinePermissionRole combines a permission and a role into a single permission level.
* Parameters:
* perm - Permission to use.
* role - Role to use.
* Returns:
* The combined permission level.
*/
func AmCombinePermissionRole(perm string, role string) uint16 {
p1 := securityRoot.permsMap[perm].level
p2 := securityRoot.roleMap[role].level
if p1 > p2 {
return p1
}
return p2
}
+1 -1
View File
@@ -27,7 +27,7 @@ type ServiceDef struct {
RequirePermission string `yaml:"requirePermission"`
RequireRole string `yaml:"requireRole"`
LinkSequence int `yaml:"linkSequence"`
Link int `yaml:"link"`
Link string `yaml:"link"`
Title string `yaml:"title"`
}