Commit b49f4e6d authored by ale's avatar ale

Remove 'public' attribute from newsletters

All newsletters are public anyway.
parent 25ee8846
Pipeline #4662 passed with stages
in 5 minutes and 26 seconds
......@@ -6,7 +6,7 @@ import (
"strconv"
"strings"
"gopkg.in/ldap.v3"
ldap "gopkg.in/ldap.v3"
as "git.autistici.org/ai3/accountserver"
)
......@@ -293,7 +293,6 @@ func (h *newsletterResourceHandler) FromLDAP(entry *ldap.Entry) (*as.Resource, e
Type: as.ResourceTypeNewsletter,
Name: listName,
Newsletter: &as.Newsletter{
Public: s2b(entry.GetAttributeValue("public")),
Admins: entry.GetAttributeValues("listOwner"),
},
}, nil
......@@ -303,7 +302,8 @@ func (h *newsletterResourceHandler) ToLDAP(rsrc *as.Resource) []ldap.PartialAttr
return []ldap.PartialAttribute{
{Type: "objectClass", Vals: []string{"top", "mailingList"}},
{Type: "listName", Vals: s2l(rsrc.Name)},
{Type: "public", Vals: s2l(b2s(rsrc.Newsletter.Public))},
// TODO: check if public is actually mandated by the schema.
{Type: "public", Vals: []string{"yes"}},
{Type: "listOwner", Vals: rsrc.Newsletter.Admins},
}
}
......
......@@ -542,20 +542,20 @@ type MailingList struct {
Public bool `json:"public"`
}
// Newsletter resource attributes.
// Newsletter resource attributes. Like a list, but with fewer
// options.
type Newsletter struct {
Admins []string `json:"admins"`
Public bool `json:"public"`
Admins []string `json:"admins"`
}
// WebDAV represents a hosting account.
type WebDAV struct {
UID int `json:"uid"`
Homedir string `json:"homedir"`
}
// Website resource attributes.
// Website resource attributes. Used for both normal websites
// (a.k.a. "subsites" of some parent domain) and domains.
type Website struct {
URL string `json:"url,omitempty"`
UID int `json:"uid"`
......
......@@ -1030,6 +1030,24 @@ func (c *templateContext) listResourceTemplate(ctx context.Context, r *Resource,
return c.setCommonResourceAttrs(ctx, r, nil, nil)
}
// Apply default values to a Newsletter resource.
func (c *templateContext) newsletterResourceTemplate(ctx context.Context, r *Resource, user *User) error {
// Force the list address to lowercase.
r.Name = strings.ToLower(r.Name)
if r.List == nil {
r.Newsletter = new(Newsletter)
}
// As a convenience, if a user is passed in the context, we add it to
// the list admins.
if user != nil && len(r.Newsletter.Admins) == 0 {
r.Newsletter.Admins = []string{user.Name}
}
return c.setCommonResourceAttrs(ctx, r, nil, nil)
}
// Apply default values to a resource.
func (c *templateContext) applyTemplate(ctx context.Context, r *Resource, user *User) error {
switch r.Type {
......@@ -1041,8 +1059,10 @@ func (c *templateContext) applyTemplate(ctx context.Context, r *Resource, user *
return c.davResourceTemplate(ctx, r, user)
case ResourceTypeDatabase:
return c.databaseResourceTemplate(ctx, r, user)
case ResourceTypeMailingList, ResourceTypeNewsletter:
case ResourceTypeMailingList:
return c.listResourceTemplate(ctx, r, user)
case ResourceTypeNewsletter:
return c.newsletterResourceTemplate(ctx, r, user)
}
return nil
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment