Skip to content

Commit

Permalink
Merge branch 'main' into fix-web/styling
Browse files Browse the repository at this point in the history
  • Loading branch information
caichi-t authored Oct 15, 2024
2 parents c56b9aa + c7c79a4 commit 804b188
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 14 deletions.
21 changes: 21 additions & 0 deletions server/e2e/integration_item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (
wId0 = accountdomain.NewWorkspaceID()
uId = accountdomain.NewUserID()
iId = id.NewIntegrationID()
mId0 = id.NewModelID()
mId1 = id.NewModelID()
mId2 = id.NewModelID()
mId3 = id.NewModelID()
Expand Down Expand Up @@ -72,7 +73,9 @@ var (
ikey2 = key.Random()
ikey3 = key.Random()
ikey4 = key.Random()
ikey0 = id.RandomKey()
pid = id.NewProjectID()
sid0 = id.NewSchemaID()
sid1 = id.NewSchemaID()
sid2 = id.NewSchemaID()
sid3 = id.NewSchemaID()
Expand Down Expand Up @@ -153,6 +156,11 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
sf3 := schema.NewField(schema.NewReference(mId1, sid1, nil, nil).TypeProperty()).ID(fId3).Key(sfKey3).MustBuild()
sf4 := schema.NewField(schema.NewBool().TypeProperty()).ID(fId4).Key(sfKey4).MustBuild()

s0 := schema.New().ID(sid0).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{}).MustBuild()
if err := r.Schema.Save(ctx, s0); err != nil {
return err
}

s1 := schema.New().ID(sid1).Workspace(w.ID()).Project(p.ID()).Fields([]*schema.Field{sf1, sf2}).TitleField(sf1.ID().Ref()).MustBuild()
if err := r.Schema.Save(ctx, s1); err != nil {
return err
Expand All @@ -168,6 +176,19 @@ func baseSeeder(ctx context.Context, r *repo.Container) error {
return err
}

m0 := model.New().
ID(mId0).
Name("m0").
Description("m0 desc").
Public(true).
Key(ikey0).
Project(p.ID()).
Schema(s0.ID()).
MustBuild()
if err := r.Model.Save(ctx, m0); err != nil {
return err
}

m1 := model.New().
ID(mId1).
Name("m1").
Expand Down
40 changes: 35 additions & 5 deletions server/e2e/integration_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,27 @@ func TestIntegrationModelUpdateAPI(t *testing.T) {
Expect().
Status(http.StatusUnauthorized)

obj := e.PATCH(endpoint, mId1).
// update empty model
obj := e.PATCH(endpoint, mId0).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": "M0 updated",
"description": "M0 desc updated",
"key": "M0KeyUpdated",
}).
Expect().
Status(http.StatusOK).
JSON().
Object()
obj.
ContainsKey("id").
ContainsKey("schemaId").
HasValue("projectId", pid).
HasValue("name", "M0 updated").
HasValue("description", "M0 desc updated").
HasValue("key", "M0KeyUpdated")

obj = e.PATCH(endpoint, mId1).
WithHeader("authorization", "Bearer "+secret).
WithJSON(map[string]interface{}{
"name": "newM1 updated",
Expand Down Expand Up @@ -187,12 +207,22 @@ func TestIntegrationModelFilterAPI(t *testing.T) {
Object().
HasValue("page", 1).
HasValue("perPage", 10).
HasValue("totalCount", 5).
HasValue("totalCount", 6).
Value("models").
Array()
models.Length().IsEqual(5)
models.Length().IsEqual(6)

obj0 := models.Value(0).Object()
obj0.
HasValue("id", mId0.String()).
HasValue("name", "m0").
HasValue("description", "m0 desc").
HasValue("public", true).
HasValue("key", ikey0.String()).
HasValue("projectId", pid).
HasValue("schemaId", sid0)

obj1 := models.Value(0).Object()
obj1 := models.Value(1).Object()
obj1.
HasValue("id", mId1.String()).
HasValue("name", "m1").
Expand All @@ -206,7 +236,7 @@ func TestIntegrationModelFilterAPI(t *testing.T) {
obj1.Value("updatedAt").NotNull()
obj1.Value("lastModified").NotNull()

obj2 := models.Value(1).Object()
obj2 := models.Value(2).Object()
obj2.
HasValue("id", mId2.String()).
HasValue("name", "m2").
Expand Down
18 changes: 14 additions & 4 deletions server/e2e/integration_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,22 @@ func TestIntegrationScemaFilterAPI(t *testing.T) {
Object().
HasValue("page", 1).
HasValue("perPage", 10).
HasValue("totalCount", 5).
HasValue("totalCount", 6).
Value("models").
Array()
models.Length().IsEqual(5)
models.Length().IsEqual(6)

obj1 := models.Value(0).Object()
obj0 := models.Value(0).Object()
obj0.
HasValue("id", mId0.String()).
HasValue("name", "m0").
HasValue("description", "m0 desc").
HasValue("public", true).
HasValue("key", ikey0.String()).
HasValue("projectId", pid).
HasValue("schemaId", sid0)

obj1 := models.Value(1).Object()
obj1.
HasValue("id", mId1.String()).
HasValue("name", "m1").
Expand All @@ -62,7 +72,7 @@ func TestIntegrationScemaFilterAPI(t *testing.T) {
obj1.Value("updatedAt").NotNull()
obj1.Value("lastModified").NotNull()

obj2 := models.Value(1).Object()
obj2 := models.Value(2).Object()
obj2.
HasValue("id", mId2.String()).
HasValue("name", "m2").
Expand Down
2 changes: 1 addition & 1 deletion server/internal/adapter/integration/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *Server) ModelUpdate(ctx context.Context, request ModelUpdateRequestObje
}

lastModified, err := uc.Item.LastModifiedByModel(ctx, request.ModelId, op)
if err != nil {
if err != nil && !errors.Is(err, rerror.ErrNotFound) {
return nil, err
}

Expand Down
11 changes: 11 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ ENV PORT=8080
# Ref: https://cloud.google.com/load-balancing/docs/https#target-proxies
ENV REAL_IP_HEADER=X-Forwarded-For

# Default values.
# Cesium Ion access token is not a secret.
ENV REEARTH_CMS_CESIUM_ION_ACCESS_TOKEN=null

# All values in reearth_config.json must have a default value.
ENV REEARTH_CMS_API=null
ENV REEARTH_CMS_COVER_IMAGE_URL=null
ENV REEARTH_CMS_EDITOR_URL=null
ENV REEARTH_CMS_LOGO_URL=null
ENV REEARTH_CMS_MULTI_TENANT=null

COPY --from=builder --chown=nginx:nginx /app/dist /usr/share/nginx/html
COPY --chown=nginx:nginx docker/nginx.conf.template /etc/nginx/templates/nginx.conf.template
COPY --chown=nginx:nginx docker/40-envsubst-on-reearth-config.sh /docker-entrypoint.d
Expand Down
9 changes: 9 additions & 0 deletions web/docker/40-envsubst-on-reearth-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ set -e
_REEARTH_CONFIG_TEMPLATE_FILE="/opt/reearth-cms/reearth_config.json.template"
_REEARTH_CONFIG_OUTPUT_FILE="/usr/share/nginx/html/reearth_config.json"

# Wrap with "" if the value doesn't start with '{' and end with '}' (JSON) or "null".
wrap_reearth_cms_variables() {
for var in $(env | grep '^REEARTH_CMS_' | cut -d= -f1); do
value=$(printenv "$var")
[ "$value" != "null" ] && ! echo "$value" | grep -qE '^\{.*\}$' && export "$var=\"${value}\""
done
}

wrap_reearth_cms_variables $@
envsubst < "$_REEARTH_CONFIG_TEMPLATE_FILE" > "$_REEARTH_CONFIG_OUTPUT_FILE"
14 changes: 10 additions & 4 deletions web/docker/reearth_config.json.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"auth0Audience": "$AUTH0_AUDIENCE",
"auth0ClientId": "$AUTH0_CLIENT_ID",
"auth0Domain": "$AUTH0_DOMAIN"
}
"api": $REEARTH_CMS_API,
"auth0Audience": $REEARTH_CMS_AUTH0_AUDIENCE,
"auth0ClientId": $REEARTH_CMS_AUTH0_CLIENT_ID,
"auth0Domain": $REEARTH_CMS_AUTH0_DOMAIN,
"cesiumIonAccessToken": $REEARTH_CMS_CESIUM_ION_ACCESS_TOKEN,
"coverImageUrl": $REEARTH_CMS_COVER_IMAGE_URL,
"editorUrl": $REEARTH_CMS_EDITOR_URL,
"logoUrl": $REEARTH_CMS_LOGO_URL,
"multiTenant": $REEARTH_CMS_MULTI_TENANT
}

0 comments on commit 804b188

Please sign in to comment.