Skip to content

Commit

Permalink
Fixes to services and links
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Aug 29, 2023
1 parent c8d7225 commit c07e9d8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 19 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
36 changes: 27 additions & 9 deletions dashboard/pkg/epinio/models/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import { EPINIO_TYPES } from '../types';
import EpinioNamespacedResource, { bulkRemove } from './epinio-namespaced-resource';

export default class EpinioServiceModel extends EpinioNamespacedResource {
constructor(...args) {
super(...args);

this.serviceDetails = {};
}

get links() {
return {
update: this.getUrl(),
Expand Down Expand Up @@ -39,16 +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 this.serviceDetails;
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;
this._serviceDetails = v;
}

// ------------------------------------------------------------------
get state() {
return this.status;
}
Expand Down Expand Up @@ -109,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 c07e9d8

Please sign in to comment.