fixed bugs in community profile

This commit is contained in:
2025-10-18 16:45:43 -06:00
parent 83bd817630
commit 94c3877819
8 changed files with 80 additions and 25 deletions
+7
View File
@@ -4,5 +4,12 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{
"name": "Launch Amsterdam",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}"
}
] ]
} }
+3 -1
View File
@@ -115,7 +115,9 @@ func ShowCommunity(ctxt ui.AmContext) (string, any, error) {
} }
tag, err := comm.LanguageTag() tag, err := comm.LanguageTag()
if err == nil && tag != nil { if err == nil && tag != nil {
ctxt.VarMap().Set("language", display.Languages(*prefs.LanguageTag()).Name(tag)) my_lang := prefs.LanguageTag()
disp := display.Languages(*my_lang)
ctxt.VarMap().Set("language", disp.Name(tag))
} }
if comm.Rules != nil && *comm.Rules != "" { if comm.Rules != nil && *comm.Rules != "" {
ctxt.VarMap().Set("rules", *comm.Rules) ctxt.VarMap().Set("rules", *comm.Rules)
+2 -2
View File
@@ -273,10 +273,10 @@ func (c *Community) SetProfileData(name string, alias string, synopsis *string,
create_lvl uint16, delete_lvl uint16, join_lvl uint16) error { create_lvl uint16, delete_lvl uint16, join_lvl uint16) error {
c.Mutex.Lock() c.Mutex.Lock()
defer c.Mutex.Unlock() defer c.Mutex.Unlock()
_, err := amdb.Exec(`UPDATE communities SET commname = ?, alias = ?, synopsis = ? rules = ?, language = ?, _, err := amdb.Exec(`UPDATE communities SET commname = ?, alias = ?, synopsis = ?, rules = ?, language = ?,
joinkey = ?, membersonly = ?, hide_dir = ?, hide_search = ?, read_lvl = ?, write_lvl = ?, create_lvl = ?, joinkey = ?, membersonly = ?, hide_dir = ?, hide_search = ?, read_lvl = ?, write_lvl = ?, create_lvl = ?,
delete_lvl = ?, join_lvl = ?, lastupdate = NOW() WHERE commid = ?`, delete_lvl = ?, join_lvl = ?, lastupdate = NOW() WHERE commid = ?`,
name, alias, synopsis, rules, joinkey, membersonly, hideDirectory, hideSearch, read_lvl, write_lvl, name, alias, synopsis, rules, language, joinkey, membersonly, hideDirectory, hideSearch, read_lvl, write_lvl,
create_lvl, delete_lvl, join_lvl, c.Id) create_lvl, delete_lvl, join_lvl, c.Id)
if err == nil { if err == nil {
c.Name = name c.Name = name
+10
View File
@@ -208,6 +208,7 @@ func (r *CfgRole) LevelStr() string {
type RoleList interface { type RoleList interface {
Roles() []Role Roles() []Role
Default() Role Default() Role
FindForLevel(uint16) Role
} }
func (r *CfgRoleList) Roles() []Role { func (r *CfgRoleList) Roles() []Role {
@@ -222,6 +223,15 @@ func (r *CfgRoleList) Default() Role {
return r.defptr return r.defptr
} }
func (r *CfgRoleList) FindForLevel(level uint16) Role {
for _, rp := range r.roleptrs {
if rp.level == level {
return rp
}
}
return nil
}
/* AmRole returns a Role given a string ID. /* AmRole returns a Role given a string ID.
* Parameters: * Parameters:
* id - ID of the role to look up. * id - ID of the role to look up.
+6
View File
@@ -112,6 +112,12 @@ func (c *amContext) ClearSession() {
// CurrentCommunity returns the current community, if one's been set. // CurrentCommunity returns the current community, if one's been set.
func (c *amContext) CurrentCommunity() *database.Community { func (c *amContext) CurrentCommunity() *database.Community {
if c.community == nil {
cv, ok := c.session.Values["lastCommunity"]
if ok && !c.CurrentUser().IsAnon {
c.SetCommunityContext(fmt.Sprintf("%d", cv))
}
}
return c.community return c.community
} }
+46 -16
View File
@@ -202,6 +202,24 @@ func (fld *DialogItem) SetInt(v int) {
fld.Value = fmt.Sprintf("%d", v) fld.Value = fmt.Sprintf("%d", v)
} }
// SetLevel sets a security level into a field value.
func (fld *DialogItem) SetLevel(level uint16) {
fld.Value = fmt.Sprintf("%d", level)
if fld.Type == "rolelist" {
rolelist := database.AmRoleList(fld.Param)
fld.AuxData = rolelist.FindForLevel(level)
}
}
// GetLevel gets a field's value as a security level.
func (fld *DialogItem) GetLevel() uint16 {
v, err := strconv.Atoi(fld.Value)
if err != nil {
return uint16(0)
}
return uint16(v)
}
// IsEmpty returns true if the field is empty. // IsEmpty returns true if the field is empty.
func (fld *DialogItem) IsEmpty() bool { func (fld *DialogItem) IsEmpty() bool {
return len(fld.Value) == 0 return len(fld.Value) == 0
@@ -278,23 +296,15 @@ func (d *Dialog) Render(ctxt AmContext) (string, any, error) {
} }
} }
case "rolelist": case "rolelist":
rl := database.AmRoleList(fld.Param) if d.Fields[i].AuxData == nil {
defv := rl.Default().LevelStr() rolelist := database.AmRoleList(fld.Param)
if d.Fields[i].Value == "" { role := rolelist.FindForLevel(d.Fields[i].GetLevel())
d.Fields[i].Value = defv if role == nil {
} else { role := rolelist.Default()
ok := false d.Fields[i].Value = role.LevelStr()
for _, r := range rl.Roles() {
if d.Fields[i].Value == r.LevelStr() {
ok = true
break
}
if !ok {
d.Fields[i].Value = defv
}
} }
d.Fields[i].AuxData = role
} }
// TODO: want to do something like dropdown but not sure what yet
} }
} }
if d.MenuSelector != "" && d.MenuSelector != "nochange" { if d.MenuSelector != "" && d.MenuSelector != "nochange" {
@@ -385,6 +395,13 @@ func (d *Dialog) LoadFromForm(ctxt AmContext) {
d.Fields[i].AuxData = dvals d.Fields[i].AuxData = dvals
case "userphoto", "communitylogo": case "userphoto", "communitylogo":
d.Fields[i].Value = ctxt.FormField(fmt.Sprintf("%s_data", fld.Name)) d.Fields[i].Value = ctxt.FormField(fmt.Sprintf("%s_data", fld.Name))
case "rolelist":
d.Fields[i].Value = ctxt.FormField(fld.Name)
rolelist := database.AmRoleList(d.Fields[i].Param)
role := rolelist.FindForLevel(d.Fields[i].GetLevel())
if role != nil {
d.Fields[i].AuxData = role
}
default: default:
d.Fields[i].Value = ctxt.FormField(fld.Name) d.Fields[i].Value = ctxt.FormField(fld.Name)
} }
@@ -510,6 +527,19 @@ func validateCountryField(fld *DialogItem) error {
return nil return nil
} }
/* validateRoleListField validates a role list field.
* Parameters:
* fld - The field to be validated.
* Returns:
* Standard Go error status.
*/
func validateRoleListField(fld *DialogItem) error {
if fld.AuxData == nil {
return fmt.Errorf("invalid role level %s found in field \"%s\"", fld.Value, fld.Caption)
}
return nil
}
/* validateDateField validates a date field. /* validateDateField validates a date field.
* Parameters: * Parameters:
* fld - The field to be validated. * fld - The field to be validated.
@@ -552,7 +582,7 @@ var validators = map[string]validatorFunc{
"integer": validateIntegerField, "integer": validateIntegerField,
"localelist": nilValidator, "localelist": nilValidator,
"password": validateTextField, "password": validateTextField,
"rolelist": nilValidator, "rolelist": validateRoleListField,
"text": validateTextField, "text": validateTextField,
"tzlist": nilValidator, "tzlist": nilValidator,
"userphoto": nilValidator, "userphoto": nilValidator,
+4 -4
View File
@@ -24,7 +24,7 @@ fields:
caption: "Community Name" caption: "Community Name"
required: true required: true
size: 32 size: 32
maxLength: 128 maxlength: 128
- type: "ams_id" - type: "ams_id"
name: "alias" name: "alias"
caption: "Community Alias" caption: "Community Alias"
@@ -35,12 +35,12 @@ fields:
name: "synopsis" name: "synopsis"
caption: "Synopsis" caption: "Synopsis"
size: 32 size: 32
maxLength: 255 maxlength: 255
- type: "text" - type: "text"
name: "rules" name: "rules"
caption: "Rules" caption: "Rules"
size: 32 size: 32
maxLength: 255 maxlength: 255
- type: "localelist" - type: "localelist"
name: "language" name: "language"
caption: "Primary Language" caption: "Primary Language"
@@ -114,7 +114,7 @@ fields:
caption: "Join Key" caption: "Join Key"
subcaption: "(for private communities)" subcaption: "(for private communities)"
size: 32 size: 32
maxLength: 64 maxlength: 64
- type: "checkbox" - type: "checkbox"
name: "membersonly" name: "membersonly"
caption: "Allow only members to access this community" caption: "Allow only members to access this community"
+2 -2
View File
@@ -114,8 +114,8 @@
{{ if isset(homePage) }} {{ if isset(homePage) }}
<div> <div>
<strong>Homepage:</strong> <strong>Homepage:</strong>
<a href="{{ homepage }}" target="_blank" <a href="{{ homePage }}" target="_blank"
class="text-blue-700 hover:text-blue-900">{{ homepage }}</a> class="text-blue-700 hover:text-blue-900">{{ homePage }}</a>
</div> </div>
{{ end }} {{ end }}
</div> </div>