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
"version": "0.2.0",
"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()
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 != "" {
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 {
c.Mutex.Lock()
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 = ?,
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)
if err == nil {
c.Name = name
+10
View File
@@ -208,6 +208,7 @@ func (r *CfgRole) LevelStr() string {
type RoleList interface {
Roles() []Role
Default() Role
FindForLevel(uint16) Role
}
func (r *CfgRoleList) Roles() []Role {
@@ -222,6 +223,15 @@ func (r *CfgRoleList) Default() Role {
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.
* Parameters:
* 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.
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>