Skip to content

Commit

Permalink
Merge pull request #318 from torchiaf/317-service-details
Browse files Browse the repository at this point in the history
Add `serviceDetails` to Service model
  • Loading branch information
torchiaf authored Aug 30, 2023
2 parents 834b47e + c07e9d8 commit abdf2ee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ func GetBaseURL(ec echo.Context) string {
return host
}

func GetSelfLink(ec echo.Context, paths ...string) string {
func GetSelfLink(ec echo.Context, additionalPaths ...string) string {
host := GetBaseURL(ec)
path := strings.Join(paths, "/")
path := strings.Join(additionalPaths, "/")

if len(path) > 0 {
path = fmt.Sprintf("/%s", path)
}

return fmt.Sprintf("https://%s%s%s", host, ec.Request().URL.String(), path)
return fmt.Sprintf("https://%s%s%s%s", host, ec.Request().URL.Host, ec.Request().URL.Path, path)
}

type AuthProvider struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GetAuthProviders(ec echo.Context, p jInterfaces.PortalProxy) error {

// /v3/users
func GetUser(ec echo.Context) error {
user := NewUser(interfaces.GetBaseURL(ec), ec.Get("user_id").(string))
user := NewUser(interfaces.GetSelfLink(ec), ec.Get("user_id").(string))

return api.SendResponse(ec, user)
}
Expand All @@ -36,7 +36,7 @@ func TokenLogout(ec echo.Context, p jInterfaces.PortalProxy) error {

// /v3/principals
func GetPrincipals(ec echo.Context) error {
principal := NewPrincipal(interfaces.GetBaseURL(ec), ec.Get("user_id").(string))
principal := NewPrincipal(interfaces.GetSelfLink(ec), ec.Get("user_id").(string))

return api.SendResponse(ec, principal)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func NewUserPref(userId string) *interfaces.UserPref {
func GetUserPrefs(c echo.Context) error {
col := NewUserPrefCollection()
col.Data = make([]interface{}, 1)
pref := createPref(c)
pref := createPref(c, true)
col.Data[0] = pref

host := interfaces.GetBaseURL(c)
base := fmt.Sprintf("https://%s%s", host, c.Request().URL.String())
base := fmt.Sprintf("https://%s%s%s", host, c.Request().URL.Host, c.Request().URL.Path)

col.Links["self"] = base

Expand All @@ -51,18 +51,25 @@ func GetUserPrefs(c echo.Context) error {

// Get user profile
func GetSpecificUserPrefs(c echo.Context) error {
return c.JSON(http.StatusOK, createPref(c))
return c.JSON(http.StatusOK, createPref(c, false))
}

func createPref(c echo.Context) *interfaces.UserPref {
func createPref(c echo.Context, isList bool) *interfaces.UserPref {
userID := c.Get("user_id").(string)

data := json.RawMessage(DefaultUserPreferences)
pref := NewUserPref(userID)
pref.Data = data

host := interfaces.GetBaseURL(c)
user := fmt.Sprintf("https://%s%s/%s", host, c.Request().URL.String(), userID)

var user string
if isList {
user = fmt.Sprintf("https://%s%s%s/%s", host, c.Request().URL.Host, c.Request().URL.Path, userID)
} else {
// Already contains user id in url
user = fmt.Sprintf("https://%s%s%s", host, c.Request().URL.Host, c.Request().URL.Path)
}

pref.Links["self"] = user
pref.Links["remove"] = user
Expand Down
34 changes: 33 additions & 1 deletion dashboard/pkg/epinio/models/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,25 @@ export default class EpinioServiceModel extends EpinioNamespacedResource {
.filter((a) => !!a);
}

// ------------------------------------------------------------------
get serviceDetails() {
return this._serviceDetails;
}

/**
* Return the dashboard reserved getter for `details` (shown in MastHead)
*/
get details() {
return super.details;
}

/**
* When assigning Epinio details property ensure it goes to a temp value (instead of colliding with dashboard reserved `details` getter)
*/
set details(v) {
this._serviceDetails = v;
}

// ------------------------------------------------------------------
get state() {
return this.status;
}
Expand Down Expand Up @@ -95,4 +112,19 @@ export default class EpinioServiceModel extends EpinioNamespacedResource {
bulkRemove(items, opt) {
return bulkRemove(items, opt);
}

// Ensure when we clone that we preserve the description
toJSON() {
const data = super.toJSON();

// Ensure the epinio detail gets persisted in the right property
data.details = this._serviceDetails;
delete data._serviceDetails;

return data;
}

toSave() {
return this.toJSON();
}
}

0 comments on commit abdf2ee

Please sign in to comment.