From ba7476dae0b3730822f42f8e62f655420e806588 Mon Sep 17 00:00:00 2001 From: Kunihiro Ishiguro Date: Fri, 11 Aug 2023 17:52:08 +0900 Subject: [PATCH] webconsole refactoring with react 18 (#47) * Apply changes for react-18. * Apply patches for react-18. * Update favicon. * Fix SubscriberCreate error when no S-NSSAI is defined. * Show proper error message. * Add webconsole to .gitignore. * Add MSISDN field in Subscription. * Make label to be consistent. * Update diff to 3.3.0. * add apiConfig as default value * Fix bug of identify admin tenant. * Fix FlowRule handling. * Fix golangci-lint error. * Remove diff to avoid confusion. * Handle non first DNN's FlowRules. * Add number of subscribers for bulk creation of the user. * Start from 1. * Set default S-NSSAI with 2 S-NSSAI configuration. * Fix Tenant Id -> Tenant Name. * Refactor again -> confirm. * Support Password Confirm feature when creating new user. * Support password confirmation in editing the user. --------- Co-authored-by: ianchen0119 --- .gitignore | 3 + backend/WebUI/api_webui.go | 78 +- backend/WebUI/routers.go | 16 + frontend/.env | 1 + frontend/.eslintrc.js | 32 + frontend/.gitignore | 42 +- frontend/.prettierrc | 9 + frontend/api/openapi.yaml | 1224 + frontend/config/env.js | 92 - frontend/config/jest/cssTransform.js | 14 - frontend/config/jest/fileTransform.js | 12 - frontend/config/paths.js | 55 - frontend/config/polyfills.js | 16 - frontend/config/webpack.config.dev.js | 287 - frontend/config/webpack.config.prod.js | 356 - frontend/config/webpackDevServer.config.js | 92 - frontend/openapi-generator.sh | 9 + frontend/package-lock.json | 66593 +++++++++++++--- frontend/package.json | 162 +- frontend/public/index.html | 40 +- frontend/public/manifest.json | 10 +- frontend/scripts/build.js | 150 - frontend/scripts/start.js | 92 - frontend/scripts/test.js | 27 - frontend/src/App.css | 38 + frontend/src/App.test.tsx | 9 + frontend/src/App.tsx | 153 + frontend/src/AppCognito.tsx | 20 + frontend/src/Blank.tsx | 5 + frontend/src/Dashboard.tsx | 160 + frontend/src/ListItems.tsx | 67 + frontend/src/LoginContext.tsx | 18 + frontend/src/ProtectedRoute.tsx | 13 + frontend/src/SimpleListMenu.tsx | 99 + frontend/src/Top.tsx | 40 + frontend/src/api/.gitignore | 4 + frontend/src/api/.npmignore | 1 + frontend/src/api/api.ts | 1112 + frontend/src/api/base.ts | 72 + frontend/src/api/common.ts | 150 + frontend/src/api/configuration.ts | 101 + frontend/src/api/git_push.sh | 57 + frontend/src/api/index.ts | 18 + frontend/src/assets/images/checkbox-1.svg | 12 - frontend/src/assets/images/checkbox-2.svg | 15 - frontend/src/assets/images/checkbox-check.svg | 16 - .../src/assets/images/checkbox-uncheck.svg | 14 - frontend/src/assets/images/default-avatar.png | Bin 2864 -> 0 bytes frontend/src/assets/images/faces/face-0.jpg | Bin 2864 -> 0 bytes frontend/src/assets/images/favicon.ico | Bin 1150 -> 0 bytes .../src/assets/images/loading-bubbles.svg | 14 - frontend/src/assets/images/mask.png | Bin 756 -> 0 bytes frontend/src/assets/images/new_logo.png | Bin 3557 -> 0 bytes frontend/src/assets/images/radio-1.svg | 12 - frontend/src/assets/images/radio-2.svg | 14 - frontend/src/assets/images/tim_80x80.png | Bin 4821 -> 0 bytes frontend/src/assets/styles/base.scss | 80 - frontend/src/assets/styles/base/_auth.scss | 50 - frontend/src/assets/styles/base/_buttons.scss | 216 - frontend/src/assets/styles/base/_card.scss | 74 - .../styles/base/_checkbox-radio-switch.scss | 211 - frontend/src/assets/styles/base/_footer.scss | 21 - frontend/src/assets/styles/base/_form.scss | 146 - frontend/src/assets/styles/base/_mixins.scss | 22 - frontend/src/assets/styles/base/_navbar.scss | 116 - .../assets/styles/base/_new_variables.scss | 0 frontend/src/assets/styles/base/_sidebar.scss | 287 - .../src/assets/styles/base/_typography.scss | 102 - .../src/assets/styles/base/_variables.scss | 272 - .../assets/styles/base/mixins/_buttons.scss | 70 - .../src/assets/styles/base/mixins/_cards.scss | 8 - .../assets/styles/base/mixins/_chartist.scss | 85 - .../src/assets/styles/base/mixins/_icons.scss | 12 - .../assets/styles/base/mixins/_inputs.scss | 17 - .../assets/styles/base/mixins/_labels.scss | 21 - .../styles/base/mixins/_morphing-buttons.scss | 34 - .../assets/styles/base/mixins/_navbars.scss | 11 - .../styles/base/mixins/_social-buttons.scss | 43 - .../src/assets/styles/base/mixins/_tabs.scss | 4 - .../styles/base/mixins/_transparency.scss | 20 - .../styles/base/mixins/_vendor-prefixes.scss | 189 - .../src/assets/styles/free5gc/global.scss | 46 - frontend/src/assets/styles/free5gc/icons.scss | 20 - .../src/assets/styles/free5gc/patches.scss | 18 - .../src/assets/styles/free5gc/spinner.scss | 72 - .../assets/styles/free5gc/subscribers.scss | 39 - .../src/assets/styles/free5gc/variables.scss | 2 - frontend/src/assets/styles/icons.scss | 442 - frontend/src/axios.tsx | 15 + .../src/components/FormInputs/Checkbox.js | 34 - frontend/src/components/FormInputs/Radio.js | 37 - .../src/components/FormInputs/TextInput.js | 34 - frontend/src/components/FormInputs/index.js | 0 .../src/components/FormInputs/renderField.js | 19 - frontend/src/components/SideBar/Nav.js | 61 - frontend/src/components/SideBar/UserInfo.js | 55 - frontend/src/components/SideBar/index.js | 34 - frontend/src/components/Switch.js | 29 - frontend/src/components/Tags.js | 42 - frontend/src/config/Constants.js | 13 - frontend/src/config/config.js | 18 - frontend/src/config/configureStore.js | 24 - frontend/src/constants/aws.tsx | 7 + frontend/src/constants/config.tsx | 4 + .../src/{assets/images => }/free5gc_logo.png | Bin frontend/src/index.css | 11 + frontend/src/index.js | 40 - frontend/src/index.tsx | 17 + frontend/src/metadata/index.js | 381 - frontend/src/models/Serializable.js | 27 - frontend/src/models/Subscriber.js | 12 - frontend/src/models/Tenant.js | 12 - frontend/src/models/UEInfo.js | 10 - frontend/src/models/UEInfoDetail.js | 14 - frontend/src/models/User.js | 20 - frontend/src/pages/AnalysisList.tsx | 111 + frontend/src/pages/App/index.js | 37 - frontend/src/pages/Auth/Login.js | 97 - frontend/src/pages/Auth/index.js | 19 - frontend/src/pages/ChangePassword.tsx | 147 + frontend/src/pages/Dashboard/index.js | 150 - frontend/src/pages/Login.tsx | 87 + frontend/src/pages/Logout.tsx | 36 + frontend/src/pages/Main/Footer.js | 23 - frontend/src/pages/Main/Header.js | 66 - frontend/src/pages/Main/index.js | 70 - frontend/src/pages/StatusList.tsx | 117 + frontend/src/pages/StatusRead.tsx | 181 + frontend/src/pages/SubscriberCreate.tsx | 1589 + frontend/src/pages/SubscriberList.tsx | 159 + frontend/src/pages/SubscriberRead.tsx | 392 + frontend/src/pages/SubscriberUpdate.tsx | 1363 + .../pages/Subscribers/SubscriberOverview.js | 167 - .../Subscribers/components/SubscriberModal.js | 430 - frontend/src/pages/Subscribers/index.js | 13 - frontend/src/pages/Tasks/TasksOverview.js | 75 - .../src/pages/Tasks/components/TasksTable.js | 73 - frontend/src/pages/Tasks/index.js | 12 - frontend/src/pages/TenantCreate.tsx | 60 + frontend/src/pages/TenantList.tsx | 159 + frontend/src/pages/TenantUpdate.tsx | 79 + frontend/src/pages/Tenants/TenantOverview.js | 132 - .../pages/Tenants/components/TenantModal.js | 106 - frontend/src/pages/Tenants/index.js | 11 - frontend/src/pages/UEInfo/index.js | 133 - frontend/src/pages/UEInfoDetail/index.js | 238 - frontend/src/pages/UserCreate.tsx | 169 + frontend/src/pages/UserList.tsx | 161 + frontend/src/pages/UserUpdate.tsx | 186 + frontend/src/pages/Users/UserOverview.js | 141 - .../src/pages/Users/components/UserModal.js | 120 - frontend/src/pages/Users/index.js | 11 - frontend/src/react-app-env.d.ts | 1 + frontend/src/redux/actions/authActions.js | 21 - .../src/redux/actions/subscriberActions.js | 16 - frontend/src/redux/actions/tenantActions.js | 11 - frontend/src/redux/actions/ueinfoActions.js | 60 - frontend/src/redux/actions/userActions.js | 11 - frontend/src/redux/reducers/auth.js | 22 - frontend/src/redux/reducers/index.js | 17 - frontend/src/redux/reducers/layout.js | 26 - frontend/src/redux/reducers/subscriber.js | 26 - frontend/src/redux/reducers/tenant.js | 26 - frontend/src/redux/reducers/ueinfo.js | 95 - frontend/src/redux/reducers/user.js | 26 - frontend/src/registerServiceWorker.js | 110 - frontend/src/reportWebVitals.ts | 15 + frontend/src/setupTests.ts | 5 + frontend/src/util/ApiHelper.js | 247 - frontend/src/util/AppUtils.js | 33 - frontend/src/util/AuthHelper.js | 41 - frontend/src/util/Http.js | 28 - frontend/src/util/LocalStorageHelper.js | 20 - frontend/src/util/UEInfoApiHelper.js | 117 - frontend/tsconfig.json | 26 + frontend/webconsole.yaml | 483 + frontend/yarn.lock | 19268 +++-- 177 files changed, 76899 insertions(+), 26338 deletions(-) create mode 100644 frontend/.env create mode 100644 frontend/.eslintrc.js create mode 100644 frontend/.prettierrc create mode 100644 frontend/api/openapi.yaml delete mode 100644 frontend/config/env.js delete mode 100644 frontend/config/jest/cssTransform.js delete mode 100644 frontend/config/jest/fileTransform.js delete mode 100644 frontend/config/paths.js delete mode 100644 frontend/config/polyfills.js delete mode 100644 frontend/config/webpack.config.dev.js delete mode 100644 frontend/config/webpack.config.prod.js delete mode 100644 frontend/config/webpackDevServer.config.js create mode 100755 frontend/openapi-generator.sh delete mode 100644 frontend/scripts/build.js delete mode 100644 frontend/scripts/start.js delete mode 100644 frontend/scripts/test.js create mode 100644 frontend/src/App.css create mode 100644 frontend/src/App.test.tsx create mode 100644 frontend/src/App.tsx create mode 100644 frontend/src/AppCognito.tsx create mode 100644 frontend/src/Blank.tsx create mode 100644 frontend/src/Dashboard.tsx create mode 100644 frontend/src/ListItems.tsx create mode 100644 frontend/src/LoginContext.tsx create mode 100644 frontend/src/ProtectedRoute.tsx create mode 100644 frontend/src/SimpleListMenu.tsx create mode 100644 frontend/src/Top.tsx create mode 100644 frontend/src/api/.gitignore create mode 100644 frontend/src/api/.npmignore create mode 100644 frontend/src/api/api.ts create mode 100644 frontend/src/api/base.ts create mode 100644 frontend/src/api/common.ts create mode 100644 frontend/src/api/configuration.ts create mode 100644 frontend/src/api/git_push.sh create mode 100644 frontend/src/api/index.ts delete mode 100644 frontend/src/assets/images/checkbox-1.svg delete mode 100644 frontend/src/assets/images/checkbox-2.svg delete mode 100644 frontend/src/assets/images/checkbox-check.svg delete mode 100644 frontend/src/assets/images/checkbox-uncheck.svg delete mode 100644 frontend/src/assets/images/default-avatar.png delete mode 100644 frontend/src/assets/images/faces/face-0.jpg delete mode 100644 frontend/src/assets/images/favicon.ico delete mode 100755 frontend/src/assets/images/loading-bubbles.svg delete mode 100755 frontend/src/assets/images/mask.png delete mode 100644 frontend/src/assets/images/new_logo.png delete mode 100644 frontend/src/assets/images/radio-1.svg delete mode 100644 frontend/src/assets/images/radio-2.svg delete mode 100644 frontend/src/assets/images/tim_80x80.png delete mode 100644 frontend/src/assets/styles/base.scss delete mode 100644 frontend/src/assets/styles/base/_auth.scss delete mode 100644 frontend/src/assets/styles/base/_buttons.scss delete mode 100644 frontend/src/assets/styles/base/_card.scss delete mode 100644 frontend/src/assets/styles/base/_checkbox-radio-switch.scss delete mode 100644 frontend/src/assets/styles/base/_footer.scss delete mode 100644 frontend/src/assets/styles/base/_form.scss delete mode 100644 frontend/src/assets/styles/base/_mixins.scss delete mode 100644 frontend/src/assets/styles/base/_navbar.scss delete mode 100644 frontend/src/assets/styles/base/_new_variables.scss delete mode 100644 frontend/src/assets/styles/base/_sidebar.scss delete mode 100644 frontend/src/assets/styles/base/_typography.scss delete mode 100644 frontend/src/assets/styles/base/_variables.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_buttons.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_cards.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_chartist.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_icons.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_inputs.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_labels.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_morphing-buttons.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_navbars.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_social-buttons.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_tabs.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_transparency.scss delete mode 100644 frontend/src/assets/styles/base/mixins/_vendor-prefixes.scss delete mode 100644 frontend/src/assets/styles/free5gc/global.scss delete mode 100644 frontend/src/assets/styles/free5gc/icons.scss delete mode 100644 frontend/src/assets/styles/free5gc/patches.scss delete mode 100644 frontend/src/assets/styles/free5gc/spinner.scss delete mode 100644 frontend/src/assets/styles/free5gc/subscribers.scss delete mode 100644 frontend/src/assets/styles/free5gc/variables.scss delete mode 100644 frontend/src/assets/styles/icons.scss create mode 100644 frontend/src/axios.tsx delete mode 100644 frontend/src/components/FormInputs/Checkbox.js delete mode 100644 frontend/src/components/FormInputs/Radio.js delete mode 100644 frontend/src/components/FormInputs/TextInput.js delete mode 100644 frontend/src/components/FormInputs/index.js delete mode 100644 frontend/src/components/FormInputs/renderField.js delete mode 100644 frontend/src/components/SideBar/Nav.js delete mode 100644 frontend/src/components/SideBar/UserInfo.js delete mode 100644 frontend/src/components/SideBar/index.js delete mode 100644 frontend/src/components/Switch.js delete mode 100644 frontend/src/components/Tags.js delete mode 100644 frontend/src/config/Constants.js delete mode 100644 frontend/src/config/config.js delete mode 100644 frontend/src/config/configureStore.js create mode 100644 frontend/src/constants/aws.tsx create mode 100644 frontend/src/constants/config.tsx rename frontend/src/{assets/images => }/free5gc_logo.png (100%) create mode 100644 frontend/src/index.css delete mode 100644 frontend/src/index.js create mode 100644 frontend/src/index.tsx delete mode 100644 frontend/src/metadata/index.js delete mode 100644 frontend/src/models/Serializable.js delete mode 100644 frontend/src/models/Subscriber.js delete mode 100644 frontend/src/models/Tenant.js delete mode 100644 frontend/src/models/UEInfo.js delete mode 100644 frontend/src/models/UEInfoDetail.js delete mode 100644 frontend/src/models/User.js create mode 100644 frontend/src/pages/AnalysisList.tsx delete mode 100644 frontend/src/pages/App/index.js delete mode 100644 frontend/src/pages/Auth/Login.js delete mode 100644 frontend/src/pages/Auth/index.js create mode 100644 frontend/src/pages/ChangePassword.tsx delete mode 100644 frontend/src/pages/Dashboard/index.js create mode 100644 frontend/src/pages/Login.tsx create mode 100644 frontend/src/pages/Logout.tsx delete mode 100644 frontend/src/pages/Main/Footer.js delete mode 100644 frontend/src/pages/Main/Header.js delete mode 100644 frontend/src/pages/Main/index.js create mode 100644 frontend/src/pages/StatusList.tsx create mode 100644 frontend/src/pages/StatusRead.tsx create mode 100644 frontend/src/pages/SubscriberCreate.tsx create mode 100644 frontend/src/pages/SubscriberList.tsx create mode 100644 frontend/src/pages/SubscriberRead.tsx create mode 100644 frontend/src/pages/SubscriberUpdate.tsx delete mode 100644 frontend/src/pages/Subscribers/SubscriberOverview.js delete mode 100644 frontend/src/pages/Subscribers/components/SubscriberModal.js delete mode 100644 frontend/src/pages/Subscribers/index.js delete mode 100644 frontend/src/pages/Tasks/TasksOverview.js delete mode 100644 frontend/src/pages/Tasks/components/TasksTable.js delete mode 100644 frontend/src/pages/Tasks/index.js create mode 100644 frontend/src/pages/TenantCreate.tsx create mode 100644 frontend/src/pages/TenantList.tsx create mode 100644 frontend/src/pages/TenantUpdate.tsx delete mode 100644 frontend/src/pages/Tenants/TenantOverview.js delete mode 100644 frontend/src/pages/Tenants/components/TenantModal.js delete mode 100644 frontend/src/pages/Tenants/index.js delete mode 100644 frontend/src/pages/UEInfo/index.js delete mode 100644 frontend/src/pages/UEInfoDetail/index.js create mode 100644 frontend/src/pages/UserCreate.tsx create mode 100644 frontend/src/pages/UserList.tsx create mode 100644 frontend/src/pages/UserUpdate.tsx delete mode 100644 frontend/src/pages/Users/UserOverview.js delete mode 100644 frontend/src/pages/Users/components/UserModal.js delete mode 100644 frontend/src/pages/Users/index.js create mode 100644 frontend/src/react-app-env.d.ts delete mode 100644 frontend/src/redux/actions/authActions.js delete mode 100644 frontend/src/redux/actions/subscriberActions.js delete mode 100644 frontend/src/redux/actions/tenantActions.js delete mode 100644 frontend/src/redux/actions/ueinfoActions.js delete mode 100644 frontend/src/redux/actions/userActions.js delete mode 100644 frontend/src/redux/reducers/auth.js delete mode 100644 frontend/src/redux/reducers/index.js delete mode 100644 frontend/src/redux/reducers/layout.js delete mode 100644 frontend/src/redux/reducers/subscriber.js delete mode 100644 frontend/src/redux/reducers/tenant.js delete mode 100644 frontend/src/redux/reducers/ueinfo.js delete mode 100644 frontend/src/redux/reducers/user.js delete mode 100644 frontend/src/registerServiceWorker.js create mode 100644 frontend/src/reportWebVitals.ts create mode 100644 frontend/src/setupTests.ts delete mode 100644 frontend/src/util/ApiHelper.js delete mode 100644 frontend/src/util/AppUtils.js delete mode 100644 frontend/src/util/AuthHelper.js delete mode 100644 frontend/src/util/Http.js delete mode 100644 frontend/src/util/LocalStorageHelper.js delete mode 100644 frontend/src/util/UEInfoApiHelper.js create mode 100644 frontend/tsconfig.json create mode 100644 frontend/webconsole.yaml diff --git a/.gitignore b/.gitignore index ddc9524e..8bf65cd4 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ cscope.* # Debug *.log *.pcap + +# Binary +webconsole diff --git a/backend/WebUI/api_webui.go b/backend/WebUI/api_webui.go index 106723af..3faa2e18 100644 --- a/backend/WebUI/api_webui.go +++ b/backend/WebUI/api_webui.go @@ -154,7 +154,7 @@ func setCorsHeader(c *gin.Context) { c.Writer.Header().Set( "Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, "+ - "X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With", + "X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Token", ) c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, PATCH, DELETE") } @@ -579,8 +579,10 @@ func ParseJWT(tokenStr string) (jwt.MapClaims, error) { func CheckAuth(c *gin.Context) bool { tokenStr := c.GetHeader("Token") claims, err := ParseJWT(tokenStr) - - if err == nil && claims["email"] == "admin" { + if err != nil { + return false + } + if claims["email"].(string) == "admin" { return true } else { return false @@ -590,9 +592,6 @@ func CheckAuth(c *gin.Context) bool { // Tenant ID func GetTenantId(c *gin.Context) (string, error) { tokenStr := c.GetHeader("Token") - if CheckAuth(c) { - return "", nil - } claims, err := ParseJWT(tokenStr) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{}) @@ -1008,8 +1007,7 @@ func GetSubscribers(c *gin.Context) { logger.ProcLog.Infoln("Get All Subscribers List") - tokenStr := c.GetHeader("Token") - claims, err := ParseJWT(tokenStr) + userTenantId, err := GetTenantId(c) if err != nil { logger.ProcLog.Errorln(err.Error()) c.JSON(http.StatusBadRequest, gin.H{ @@ -1018,6 +1016,8 @@ func GetSubscribers(c *gin.Context) { return } + isAdmin := CheckAuth(c) + var subsList []SubsListIE = make([]SubsListIE, 0) amDataList, err := mongoapi.RestfulAPIGetMany(amDataColl, bson.M{}) if err != nil { @@ -1047,7 +1047,7 @@ func GetSubscribers(c *gin.Context) { return } - if claims["email"] == "admin" || tenantId == claims["tenantId"].(string) { + if isAdmin || userTenantId == tenantId { tmp := SubsListIE{ PlmnID: servingPlmnId.(string), UeId: ueId.(string), @@ -1670,6 +1670,8 @@ func GetRegisteredUEContext(c *gin.Context) { webuiSelf := webui_context.GetSelf() webuiSelf.UpdateNfProfiles() + isAdmin := CheckAuth(c) + supi, supiExists := c.Params.Get("supi") // TODO: support fetching data from multiple AMFs if amfUris := webuiSelf.GetOamUris(models.NfType_AMF); amfUris != nil { @@ -1709,7 +1711,7 @@ func GetRegisteredUEContext(c *gin.Context) { return } - if tenantId == "" { + if isAdmin { sendResponseToClient(c, resp) } else { sendResponseToClientFilterTenant(c, resp, tenantId) @@ -1763,3 +1765,59 @@ func GetUEPDUSessionInfo(c *gin.Context) { }) } } + +func ChangePasswordInfo(c *gin.Context) { + setCorsHeader(c) + + // Need to get tenantId. + tenantId, err := GetTenantId(c) + if err != nil { + logger.ProcLog.Errorln(err.Error()) + c.JSON(http.StatusBadRequest, gin.H{}) + return + } + + var newUserData User + if err = c.ShouldBindJSON(&newUserData); err != nil { + logger.ProcLog.Errorln(err.Error()) + c.JSON(http.StatusBadRequest, gin.H{}) + return + } + + filterEmailOnly := bson.M{"tenantId": tenantId, "email": newUserData.Email} + userDataInterface, err := mongoapi.RestfulAPIGetOne(userDataColl, filterEmailOnly) + if err != nil { + logger.ProcLog.Errorf("ChangePassword err: %+v", err) + } + if len(userDataInterface) == 0 { + c.JSON(http.StatusNotFound, bson.M{}) + return + } + + var userData User + err = json.Unmarshal(mapToByte(userDataInterface), &userData) + if err != nil { + logger.ProcLog.Errorf("JSON Unmarshal err: %+v", err) + } + + if newUserData.EncryptedPassword != "" { + hash, err := bcrypt.GenerateFromPassword([]byte(newUserData.EncryptedPassword), 12) + if err != nil { + logger.ProcLog.Errorf("GenerateFromPassword err: %+v", err) + } + userData.EncryptedPassword = string(hash) + } + + userBsonM := toBsonM(userData) + if _, err := mongoapi.RestfulAPIPost(userDataColl, filterEmailOnly, userBsonM); err != nil { + logger.ProcLog.Errorf("PutUserByID err: %+v", err) + } + + c.JSON(http.StatusOK, userData) +} + +func OptionsSubscribers(c *gin.Context) { + setCorsHeader(c) + + c.JSON(http.StatusNoContent, gin.H{}) +} diff --git a/backend/WebUI/routers.go b/backend/WebUI/routers.go index a3ab212c..9ab43ba1 100644 --- a/backend/WebUI/routers.go +++ b/backend/WebUI/routers.go @@ -46,6 +46,8 @@ func AddService(engine *gin.Engine) *gin.RouterGroup { group.DELETE(route.Pattern, route.HandlerFunc) case http.MethodPatch: group.PATCH(route.Pattern, route.HandlerFunc) + case http.MethodOptions: + group.OPTIONS(route.Pattern, route.HandlerFunc) } } @@ -151,6 +153,13 @@ var routes = Routes{ GetSubscribers, }, + { + "OptionsSubscribers", + http.MethodOptions, + "/subscriber", + OptionsSubscribers, + }, + { "GetSubscriberByID", http.MethodGet, @@ -213,4 +222,11 @@ var routes = Routes{ "/ue-pdu-session-info/:smContextRef", GetUEPDUSessionInfo, }, + + { + "Change Password", + http.MethodPost, + "/change-password", + ChangePasswordInfo, + }, } diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 00000000..ba7cc18d --- /dev/null +++ b/frontend/.env @@ -0,0 +1 @@ +GENERATE_SOURCEMAP=false diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js new file mode 100644 index 00000000..052ccffe --- /dev/null +++ b/frontend/.eslintrc.js @@ -0,0 +1,32 @@ +module.exports = { + "env": { + "browser": true, + "es2021": true + }, + "root": true, + "extends": [ + "airbnb-typescript/base", + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module", + "project": "./tsconfig.json" + }, + "plugins": [ + "react", + "@typescript-eslint", + "import" + ], + "rules": { + "@typescript-eslint/no-non-null-assertion": 0, + "@typescript-eslint/no-explicit-any": 0, + "import/extensions": "off" + } +} diff --git a/frontend/.gitignore b/frontend/.gitignore index e430f411..c37ff00e 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -1,3 +1,41 @@ -node_modules +## openapi-generate +**/.DS_Store +/node_modules +/.pnp +.pnp.js +/build +.env.local +.env.development.local +.env.test.local +.env.production.local +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.openapi-generator-ignore +.openapi-generator/ +mdm +README.md -build \ No newline at end of file +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/frontend/.prettierrc b/frontend/.prettierrc new file mode 100644 index 00000000..e67f1053 --- /dev/null +++ b/frontend/.prettierrc @@ -0,0 +1,9 @@ +{ + "semi": true, + "tabWidth": 2, + "printWidth": 100, + "singleQuote": false, + "trailingComma": "all", + "jsxSingleQuote": false, + "bracketSpacing": true +} diff --git a/frontend/api/openapi.yaml b/frontend/api/openapi.yaml new file mode 100644 index 00000000..984496e6 --- /dev/null +++ b/frontend/api/openapi.yaml @@ -0,0 +1,1224 @@ +openapi: 3.0.0 +info: + description: MDM backend API + title: MDM Backend API + version: v1 +servers: +- url: http://localhost:9090 +tags: +- description: MDM backend API + name: mdm +- description: MDM dashboard API for services + name: services +- description: MDM dashboard API for apps + name: apps +- description: MDM dashboard API for devices + name: devices +- description: MDM dashboard API for files + name: files +- description: MDM dashboard API for logs + name: logs +- description: MDM test API + name: tests +paths: + /api/v1/postDeviceInfo: + post: + description: Register device information API + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/DeviceInfoRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/DeviceInfoResponse' + description: Recommendation response + summary: Register device information + tags: + - mdm + /api/v1/queryDeviceManage: + post: + description: Register device information API + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/DeviceManageRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/DeviceManageResponse' + description: Recommendation response + summary: Register device information + tags: + - mdm + /api/v1/getSoftwareInfo: + post: + description: Register device information API + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GetSoftwareRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GetSoftwareResponse' + description: Recommendation response + summary: Register device information + tags: + - mdm + /api/v1/postLog: + post: + description: Register device information API + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PostLogRequest' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/PostLogResponse' + description: Recommendation response + summary: Register device information + tags: + - mdm + /services: + get: + description: Returns an array of services. + parameters: + - explode: true + in: query + name: limit + required: false + schema: + format: int64 + type: integer + style: form + - explode: true + in: query + name: page + required: false + schema: + format: int64 + type: integer + style: form + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/ServicesList' + description: Returns an array of service. + summary: Get all services. + tags: + - services + options: + description: Add a new service + responses: + "204": + description: No Content + summary: Add a service + tags: + - services + post: + description: Add a new service + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Services' + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/Services' + description: Created + summary: Add a service + tags: + - services + /services/{serviceId}: + delete: + description: Deletes a service + parameters: + - description: ID of service to delete + explode: false + in: path + name: serviceId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + description: Deleted + "400": + description: Invalid ID supplied + "404": + description: Service not found + summary: Deletes a service + tags: + - services + get: + description: Return a service. + parameters: + - description: ID of service to return + explode: false + in: path + name: serviceId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Services' + description: A JSON of the service + summary: Get service. + tags: + - services + put: + description: Update a service + parameters: + - description: ID of service to update + explode: false + in: path + name: serviceId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Services' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Services' + description: Updated + summary: Update a service + tags: + - services + /apps: + get: + description: Returns an array of apps. + parameters: + - explode: true + in: query + name: limit + required: false + schema: + format: int64 + type: integer + style: form + - explode: true + in: query + name: page + required: false + schema: + format: int64 + type: integer + style: form + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/AppsList' + description: Returns an array of app. + summary: Get all apps. + tags: + - apps + options: + description: Add a new app + responses: + "204": + description: No Content + summary: Add a app + tags: + - apps + post: + description: Add a new app + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Apps' + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/Apps' + description: Created + summary: Add a app + tags: + - apps + /apps/{appId}: + delete: + description: Deletes a app + parameters: + - description: ID of app to delete + explode: false + in: path + name: appId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + description: Deleted + "400": + description: Invalid ID supplied + "404": + description: App not found + summary: Deletes a app + tags: + - apps + get: + description: Return a app. + parameters: + - description: ID of app to return + explode: false + in: path + name: appId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Apps' + description: A JSON of the app + summary: Get app. + tags: + - apps + put: + description: Update a app + parameters: + - description: ID of app to update + explode: false + in: path + name: appId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Apps' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Apps' + description: Updated + summary: Update a app + tags: + - apps + /devices: + get: + description: Returns an array of devices. + parameters: + - explode: true + in: query + name: limit + required: false + schema: + format: int64 + type: integer + style: form + - explode: true + in: query + name: page + required: false + schema: + format: int64 + type: integer + style: form + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/DevicesList' + description: Returns an array of device. + summary: Get all devices. + tags: + - devices + options: + description: Add a new device + responses: + "204": + description: No Content + summary: Add a device + tags: + - devices + post: + description: Add a new device + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Devices' + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/Devices' + description: Created + summary: Add a device + tags: + - devices + /devices/{deviceId}: + delete: + description: Deletes a device + parameters: + - description: ID of device to delete + explode: false + in: path + name: deviceId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + description: Deleted + "400": + description: Invalid ID supplied + "404": + description: Device not found + summary: Deletes a device + tags: + - devices + get: + description: Return a device. + parameters: + - description: ID of device to return + explode: false + in: path + name: deviceId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Devices' + description: A JSON of the device + summary: Get device. + tags: + - devices + put: + description: Update a device + parameters: + - description: ID of device to update + explode: false + in: path + name: deviceId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Devices' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Devices' + description: Updated + summary: Update a device + tags: + - devices + /files: + get: + description: Returns an array of files. + parameters: + - explode: true + in: query + name: limit + required: false + schema: + format: int64 + type: integer + style: form + - explode: true + in: query + name: page + required: false + schema: + format: int64 + type: integer + style: form + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/FilesList' + description: Returns an array of file. + summary: Get all files. + tags: + - files + options: + description: Add a new file + responses: + "204": + description: No Content + summary: Add a file + tags: + - files + post: + description: Add a new file + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Files' + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/Files' + description: Created + summary: Add a file + tags: + - files + /files/{fileId}: + delete: + description: Deletes a file + parameters: + - description: ID of file to delete + explode: false + in: path + name: fileId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + description: Deleted + "400": + description: Invalid ID supplied + "404": + description: File not found + summary: Deletes a file + tags: + - files + get: + description: Return a file. + parameters: + - description: ID of file to return + explode: false + in: path + name: fileId + required: true + schema: + format: int64 + type: integer + style: simple + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Files' + description: A JSON of the file + summary: Get file. + tags: + - files + put: + description: Update a file + parameters: + - description: ID of file to update + explode: false + in: path + name: fileId + required: true + schema: + format: int64 + type: integer + style: simple + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Files' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/Files' + description: Updated + summary: Update a file + tags: + - files + /logs: + options: + description: Dump logs + responses: + "204": + description: No Content + summary: Dump logs + tags: + - logs + post: + description: Dump logs + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/LogsRequest' + responses: + "201": + content: + application/json: + schema: + $ref: '#/components/schemas/LogsResponse' + description: Created + summary: Dump logs + tags: + - logs +components: + schemas: + Meta: + example: + next: next + total: 6 + prev: prev + limit: 0 + properties: + next: + type: string + prev: + type: string + limit: + format: int64 + type: integer + total: + format: int64 + type: integer + type: object + DeviceInfoRequest: + example: + iccid: iccid + device_id: device_id + app_version: app_version + model_name: model_name + app_build_number: app_build_number + service_id: service_id + os_version: os_version + imei: imei + root_exploit: true + imsi: imsi + app_id: app_id + properties: + device_id: + type: string + service_id: + type: string + app_id: + type: string + app_version: + type: string + app_build_number: + type: string + iccid: + type: string + imei: + type: string + imsi: + type: string + model_name: + type: string + os_version: + type: string + root_exploit: + type: boolean + type: object + Empty: + type: object + DeviceInfoResponse: + example: + result: 0 + response: "{}" + currentTimestamp: 6 + properties: + result: + format: int64 + type: integer + response: + type: object + currentTimestamp: + format: int64 + type: integer + type: object + DeviceManageRequest: + example: + device_id: device_id + app_version: app_version + app_build_number: app_build_number + service_id: service_id + app_id: app_id + properties: + device_id: + type: string + service_id: + type: string + app_id: + type: string + app_version: + type: string + app_build_number: + type: string + type: object + DeviceManageData: + example: + device_available: true + service_available: true + kiosk_mode_enabled: true + properties: + kiosk_mode_enabled: + type: boolean + device_available: + type: boolean + service_available: + type: boolean + type: object + DeviceManageResponse: + example: + result: 0 + response: + device_available: true + service_available: true + kiosk_mode_enabled: true + currentTimestamp: 6 + properties: + result: + format: int64 + type: integer + response: + $ref: '#/components/schemas/DeviceManageData' + currentTimestamp: + format: int64 + type: integer + type: object + GetSoftwareApp: + example: + file_hash: file_hash + version: version + url: url + properties: + version: + type: string + url: + type: string + file_hash: + type: string + type: object + GetSoftwareFile: + example: + file_hash: file_hash + version: version + key: key + url: url + properties: + key: + type: string + version: + type: string + url: + type: string + file_hash: + type: string + type: object + GetSoftwareData: + example: + app: + file_hash: file_hash + version: version + url: url + file: + - file_hash: file_hash + version: version + key: key + url: url + - file_hash: file_hash + version: version + key: key + url: url + properties: + app: + $ref: '#/components/schemas/GetSoftwareApp' + file: + items: + $ref: '#/components/schemas/GetSoftwareFile' + type: array + type: object + GetSoftwareRequest: + example: + device_id: device_id + app_version: app_version + app_build_number: app_build_number + service_id: service_id + app_id: app_id + properties: + device_id: + type: string + service_id: + type: string + app_id: + type: string + app_version: + type: string + app_build_number: + type: string + type: object + GetSoftwareResponse: + example: + result: 0 + response: + app: + file_hash: file_hash + version: version + url: url + file: + - file_hash: file_hash + version: version + key: key + url: url + - file_hash: file_hash + version: version + key: key + url: url + currentTimestamp: 6 + properties: + result: + format: int64 + type: integer + response: + $ref: '#/components/schemas/GetSoftwareData' + currentTimestamp: + format: int64 + type: integer + type: object + PostLogRequest: + example: + device_id: device_id + app_version: app_version + log: log + app_build_number: app_build_number + service_id: service_id + app_id: app_id + properties: + device_id: + type: string + service_id: + type: string + app_id: + type: string + app_version: + type: string + app_build_number: + type: string + log: + type: string + type: object + PostLogResponse: + example: + result: 0 + response: "{}" + currentTimestamp: 6 + properties: + result: + format: int64 + type: integer + response: + type: object + currentTimestamp: + format: int64 + type: integer + type: object + Accounts: + properties: + id: + format: int64 + type: integer + email: + type: string + created_at: + type: time + updated_at: + type: time + type: object + Devices: + example: + device_id: device_id + app_version: app_version + service_available: true + os_version: os_version + root_exploit: true + created_at: "" + imsi: imsi + iccid: iccid + model_name: model_name + device_available: true + updated_at: "" + app_build_number: app_build_number + service_id: service_id + imei: imei + id: 0 + app_id: app_id + kiosk_mode_enabled: true + properties: + id: + format: int64 + type: integer + device_id: + type: string + service_id: + type: string + app_id: + type: string + app_version: + type: string + app_build_number: + type: string + iccid: + type: string + imei: + type: string + imsi: + type: string + model_name: + type: string + os_version: + type: string + root_exploit: + type: boolean + kiosk_mode_enabled: + type: boolean + device_available: + type: boolean + service_available: + type: boolean + created_at: + type: time + updated_at: + type: time + type: object + Services: + example: + updated_at: "" + service_name: service_name + service_id: service_id + memo: memo + created_at: "" + id: 1 + properties: + id: + format: int64 + type: integer + service_id: + type: string + service_name: + type: string + memo: + type: string + created_at: + type: time + updated_at: + type: time + type: object + Apps: + example: + app_name: app_name + app_version: app_version + updated_at: "" + service_id: service_id + memo: memo + created_at: "" + id: 0 + app_id: app_id + properties: + id: + format: int64 + type: integer + service_id: + type: string + app_id: + type: string + app_name: + type: string + app_version: + type: string + memo: + type: string + created_at: + type: time + updated_at: + type: time + type: object + Files: + example: + file_version: file_version + file_key: file_key + file_path: file_path + file_hash: file_hash + updated_at: "" + created_at: "" + id: 0 + app_id: app_id + properties: + id: + format: int64 + type: integer + app_id: + type: string + file_key: + type: string + file_version: + type: string + file_path: + type: string + file_hash: + type: string + created_at: + type: time + updated_at: + type: time + type: object + Logs: + properties: + id: + format: int64 + type: integer + device_id: + type: string + service_id: + type: string + app_id: + type: string + app_version: + type: string + app_build_number: + type: string + logs: + type: string + created_at: + type: time + type: object + ServicesList: + example: + meta: + next: next + total: 6 + prev: prev + limit: 0 + response: + - updated_at: "" + service_name: service_name + service_id: service_id + memo: memo + created_at: "" + id: 1 + - updated_at: "" + service_name: service_name + service_id: service_id + memo: memo + created_at: "" + id: 1 + properties: + meta: + $ref: '#/components/schemas/Meta' + response: + items: + $ref: '#/components/schemas/Services' + type: array + type: object + AppsList: + example: + meta: + next: next + total: 6 + prev: prev + limit: 0 + response: + - app_name: app_name + app_version: app_version + updated_at: "" + service_id: service_id + memo: memo + created_at: "" + id: 0 + app_id: app_id + - app_name: app_name + app_version: app_version + updated_at: "" + service_id: service_id + memo: memo + created_at: "" + id: 0 + app_id: app_id + properties: + meta: + $ref: '#/components/schemas/Meta' + response: + items: + $ref: '#/components/schemas/Apps' + type: array + type: object + DevicesList: + example: + meta: + next: next + total: 6 + prev: prev + limit: 0 + response: + - device_id: device_id + app_version: app_version + service_available: true + os_version: os_version + root_exploit: true + created_at: "" + imsi: imsi + iccid: iccid + model_name: model_name + device_available: true + updated_at: "" + app_build_number: app_build_number + service_id: service_id + imei: imei + id: 0 + app_id: app_id + kiosk_mode_enabled: true + - device_id: device_id + app_version: app_version + service_available: true + os_version: os_version + root_exploit: true + created_at: "" + imsi: imsi + iccid: iccid + model_name: model_name + device_available: true + updated_at: "" + app_build_number: app_build_number + service_id: service_id + imei: imei + id: 0 + app_id: app_id + kiosk_mode_enabled: true + properties: + meta: + $ref: '#/components/schemas/Meta' + response: + items: + $ref: '#/components/schemas/Devices' + type: array + type: object + FilesList: + example: + meta: + next: next + total: 6 + prev: prev + limit: 0 + response: + - file_version: file_version + file_key: file_key + file_path: file_path + file_hash: file_hash + updated_at: "" + created_at: "" + id: 0 + app_id: app_id + - file_version: file_version + file_key: file_key + file_path: file_path + file_hash: file_hash + updated_at: "" + created_at: "" + id: 0 + app_id: app_id + properties: + meta: + $ref: '#/components/schemas/Meta' + response: + items: + $ref: '#/components/schemas/Files' + type: array + type: object + LogsRequest: + example: + device_id: device_id + start: start + end: end + properties: + device_id: + type: string + start: + type: string + end: + type: string + type: object + LogsResponse: + example: + result: 0 + file_name: file_name + properties: + result: + format: int64 + type: integer + file_name: + type: string + type: object diff --git a/frontend/config/env.js b/frontend/config/env.js deleted file mode 100644 index 9ce4ec7c..00000000 --- a/frontend/config/env.js +++ /dev/null @@ -1,92 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const paths = require('./paths'); -require('dotenv').config(); -// Make sure that including paths.js after env.js will read .env variables. -delete require.cache[require.resolve('./paths')]; - -const NODE_ENV = process.env.NODE_ENV; -if (!NODE_ENV) { - throw new Error( - 'The NODE_ENV environment variable is required but was not specified.' - ); -} - -// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use -var dotenvFiles = [ - `${paths.dotenv}.${NODE_ENV}.local`, - `${paths.dotenv}.${NODE_ENV}`, - // Don't include `.env.local` for `test` environment - // since normally you expect tests to produce the same - // results for everyone - NODE_ENV !== 'test' && `${paths.dotenv}.local`, - paths.dotenv, -].filter(Boolean); - -// Load environment variables from .env* files. Suppress warnings using silent -// if this file is missing. dotenv will never modify any environment variables -// that have already been set. -// https://github.com/motdotla/dotenv -dotenvFiles.forEach(dotenvFile => { - if (fs.existsSync(dotenvFile)) { - require('dotenv').config({ - path: dotenvFile, - }); - } -}); - -// We support resolving modules according to `NODE_PATH`. -// This lets you use absolute paths in imports inside large monorepos: -// https://github.com/facebookincubator/create-react-app/issues/253. -// It works similar to `NODE_PATH` in Node itself: -// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders -// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored. -// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims. -// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421 -// We also resolve them to make sure all tools using them work consistently. -const appDirectory = fs.realpathSync(process.cwd()); -process.env.NODE_PATH = (process.env.NODE_PATH || '') - .split(path.delimiter) - .filter(folder => folder && !path.isAbsolute(folder)) - .map(folder => path.resolve(appDirectory, folder)) - .join(path.delimiter); - -// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be -// injected into the application via DefinePlugin in Webpack configuration. -const REACT_APP = /^REACT_APP_/i; - -function getClientEnvironment(publicUrl) { - const raw = Object.keys(process.env) - .filter(key => REACT_APP.test(key)) - .reduce( - (env, key) => { - env[key] = process.env[key]; - return env; - }, - { - // Useful for determining whether we’re running in production mode. - // Most importantly, it switches React into the correct mode. - NODE_ENV: process.env.NODE_ENV || 'development', - // Useful for resolving the correct path to static assets in `public`. - // For example, . - // This should only be used as an escape hatch. Normally you would put - // images into the `src` and `import` them in code to get their paths. - PUBLIC_URL: publicUrl, - API_URL: process.env.API_URL, - MapboxAccessToken: process.env.MapboxAccessToken - } - ); - // Stringify all values so we can feed into Webpack DefinePlugin - const stringified = { - 'process.env': Object.keys(raw).reduce((env, key) => { - env[key] = JSON.stringify(raw[key]); - return env; - }, {}), - }; - - return { raw, stringified }; -} - -module.exports = getClientEnvironment; diff --git a/frontend/config/jest/cssTransform.js b/frontend/config/jest/cssTransform.js deleted file mode 100644 index f1534f6f..00000000 --- a/frontend/config/jest/cssTransform.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -// This is a custom Jest transformer turning style imports into empty objects. -// http://facebook.github.io/jest/docs/tutorial-webpack.html - -module.exports = { - process() { - return 'module.exports = {};'; - }, - getCacheKey() { - // The output is always the same. - return 'cssTransform'; - }, -}; diff --git a/frontend/config/jest/fileTransform.js b/frontend/config/jest/fileTransform.js deleted file mode 100644 index ffce0da2..00000000 --- a/frontend/config/jest/fileTransform.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -const path = require('path'); - -// This is a custom Jest transformer turning file imports into filenames. -// http://facebook.github.io/jest/docs/tutorial-webpack.html - -module.exports = { - process(src, filename) { - return `module.exports = ${JSON.stringify(path.basename(filename))};`; - }, -}; diff --git a/frontend/config/paths.js b/frontend/config/paths.js deleted file mode 100644 index 6d16efc9..00000000 --- a/frontend/config/paths.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; - -const path = require('path'); -const fs = require('fs'); -const url = require('url'); - -// Make sure any symlinks in the project folder are resolved: -// https://github.com/facebookincubator/create-react-app/issues/637 -const appDirectory = fs.realpathSync(process.cwd()); -const resolveApp = relativePath => path.resolve(appDirectory, relativePath); - -const envPublicUrl = process.env.PUBLIC_URL; - -function ensureSlash(path, needsSlash) { - const hasSlash = path.endsWith('/'); - if (hasSlash && !needsSlash) { - return path.substr(path, path.length - 1); - } else if (!hasSlash && needsSlash) { - return `${path}/`; - } else { - return path; - } -} - -const getPublicUrl = appPackageJson => - envPublicUrl || require(appPackageJson).homepage; - -// We use `PUBLIC_URL` environment variable or "homepage" field to infer -// "public path" at which the app is served. -// Webpack needs to know it to put the right