Commit da871e97 authored by ale's avatar ale

Add an explicit Type field to Resources

The type is already encoded in the resource ID, but this is handy for API clients so that they do not need to parse resource IDs.
parent 3ae8fb58
Pipeline #1071 passed with stages
in 1 minute 30 seconds
......@@ -94,6 +94,7 @@ func TestModel_GetUser(t *testing.T) {
"alias=uno",
"unodb",
),
Type: accountserver.ResourceTypeDatabase,
ParentID: accountserver.NewResourceID(
accountserver.ResourceTypeWebsite,
testUser1,
......
......@@ -161,6 +161,7 @@ func (h *emailResourceHandler) FromLDAP(entry *ldap.Entry) (*accountserver.Resou
username,
email,
),
Type: accountserver.ResourceTypeEmail,
Name: email,
Email: &accountserver.Email{
Aliases: entry.GetAttributeValues("mailAlternateAddr"),
......@@ -206,6 +207,7 @@ func (h *mailingListResourceHandler) FromLDAP(entry *ldap.Entry) (*accountserver
listName := entry.GetAttributeValue("listName")
return &accountserver.Resource{
ID: accountserver.NewResourceID(accountserver.ResourceTypeMailingList, listName),
Type: accountserver.ResourceTypeMailingList,
Name: listName,
List: &accountserver.MailingList{
Public: s2b(entry.GetAttributeValue("public")),
......@@ -269,6 +271,7 @@ func (h *websiteResourceHandler) FromLDAP(entry *ldap.Entry) (*accountserver.Res
username,
alias,
),
Type: accountserver.ResourceTypeWebsite,
Name: name,
Website: &accountserver.Website{
URL: url,
......@@ -335,6 +338,7 @@ func (h *domainResourceHandler) FromLDAP(entry *ldap.Entry) (*accountserver.Reso
username,
cn,
),
Type: accountserver.ResourceTypeDomain,
Name: cn,
Website: &accountserver.Website{
URL: fmt.Sprintf("https://%s/", cn),
......@@ -398,6 +402,7 @@ func (h *webdavResourceHandler) FromLDAP(entry *ldap.Entry) (*accountserver.Reso
username,
name,
),
Type: accountserver.ResourceTypeDAV,
Name: name,
DAV: &accountserver.WebDAV{
Homedir: entry.GetAttributeValue("homeDirectory"),
......@@ -504,6 +509,7 @@ func (h *databaseResourceHandler) FromLDAP(entry *ldap.Entry) (*accountserver.Re
}
return &accountserver.Resource{
ID: rsrcID,
Type: accountserver.ResourceTypeDatabase,
ParentID: parentID,
Name: name,
Database: &accountserver.Database{
......
......@@ -33,6 +33,7 @@ func TestEmailResource_FromLDAP(t *testing.T) {
expected := &accountserver.Resource{
ID: accountserver.NewResourceID("email", "test@investici.org", "test@investici.org"),
Type: "email",
Name: "test@investici.org",
Status: "active",
Shard: "host1",
......
......@@ -239,6 +239,10 @@ type Resource struct {
// IDs).
ID ResourceID `json:"id"`
// Resource type. This simply repeats the value of ID.Type but
// is useful when exporting to JSON.
Type string `json:"type"`
// Name of the resource, used for display purposes.
Name string `json:"name"`
......
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