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
+6
View File
@@ -112,6 +112,12 @@ func (c *amContext) ClearSession() {
// CurrentCommunity returns the current community, if one's been set.
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
}
+46 -16
View File
@@ -202,6 +202,24 @@ func (fld *DialogItem) SetInt(v int) {
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.
func (fld *DialogItem) IsEmpty() bool {
return len(fld.Value) == 0
@@ -278,23 +296,15 @@ func (d *Dialog) Render(ctxt AmContext) (string, any, error) {
}
}
case "rolelist":
rl := database.AmRoleList(fld.Param)
defv := rl.Default().LevelStr()
if d.Fields[i].Value == "" {
d.Fields[i].Value = defv
} else {
ok := false
for _, r := range rl.Roles() {
if d.Fields[i].Value == r.LevelStr() {
ok = true
break
}
if !ok {
d.Fields[i].Value = defv
}
if d.Fields[i].AuxData == nil {
rolelist := database.AmRoleList(fld.Param)
role := rolelist.FindForLevel(d.Fields[i].GetLevel())
if role == nil {
role := rolelist.Default()
d.Fields[i].Value = role.LevelStr()
}
d.Fields[i].AuxData = role
}
// TODO: want to do something like dropdown but not sure what yet
}
}
if d.MenuSelector != "" && d.MenuSelector != "nochange" {
@@ -385,6 +395,13 @@ func (d *Dialog) LoadFromForm(ctxt AmContext) {
d.Fields[i].AuxData = dvals
case "userphoto", "communitylogo":
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:
d.Fields[i].Value = ctxt.FormField(fld.Name)
}
@@ -510,6 +527,19 @@ func validateCountryField(fld *DialogItem) error {
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.
* Parameters:
* fld - The field to be validated.
@@ -552,7 +582,7 @@ var validators = map[string]validatorFunc{
"integer": validateIntegerField,
"localelist": nilValidator,
"password": validateTextField,
"rolelist": nilValidator,
"rolelist": validateRoleListField,
"text": validateTextField,
"tzlist": nilValidator,
"userphoto": nilValidator,
+4 -4
View File
@@ -24,7 +24,7 @@ fields:
caption: "Community Name"
required: true
size: 32
maxLength: 128
maxlength: 128
- type: "ams_id"
name: "alias"
caption: "Community Alias"
@@ -35,12 +35,12 @@ fields:
name: "synopsis"
caption: "Synopsis"
size: 32
maxLength: 255
maxlength: 255
- type: "text"
name: "rules"
caption: "Rules"
size: 32
maxLength: 255
maxlength: 255
- type: "localelist"
name: "language"
caption: "Primary Language"
@@ -114,7 +114,7 @@ fields:
caption: "Join Key"
subcaption: "(for private communities)"
size: 32
maxLength: 64
maxlength: 64
- type: "checkbox"
name: "membersonly"
caption: "Allow only members to access this community"
+2 -2
View File
@@ -114,8 +114,8 @@
{{ if isset(homePage) }}
<div>
<strong>Homepage:</strong>
<a href="{{ homepage }}" target="_blank"
class="text-blue-700 hover:text-blue-900">{{ homepage }}</a>
<a href="{{ homePage }}" target="_blank"
class="text-blue-700 hover:text-blue-900">{{ homePage }}</a>
</div>
{{ end }}
</div>