• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1648176235

30 Jan 2025 09:44AM UTC coverage: 77.589% (+1.0%) from 76.604%
1648176235

Pull #390

gitlab-ci

mzedel
fix(gui): made tenant creation form also work with unset SP device limits

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #390: MEN-7961 - SP config fixes

4329 of 6285 branches covered (68.88%)

Branch coverage included in aggregate %.

26 of 34 new or added lines in 6 files covered. (76.47%)

2 existing lines in 1 file now uncovered.

42773 of 54422 relevant lines covered (78.6%)

21.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/frontend/src/js/config/routes.tsx
1
// Copyright 2015 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14
import React, { ReactElement } from 'react';
15
import { Navigate, Outlet, Route, Routes, useLocation } from 'react-router-dom';
16

17
import AuditLogs from '../components/auditlogs/AuditLogs';
18
import Dashboard from '../components/dashboard/Dashboard';
19
import Deployments from '../components/deployments/Deployments';
20
import Devices from '../components/devices/DeviceGroups';
21
import Help from '../components/help/Help';
22
import Login from '../components/login/Login';
23
import Password from '../components/login/Password';
24
import PasswordReset from '../components/login/PasswordReset';
25
import Signup from '../components/login/Signup';
26
import Releases from '../components/releases/Releases';
27
import Settings from '../components/settings/Settings';
28
import { TenantPage } from '../components/tenants/TenantPage';
29

30
type RouteConfig = { path: string; element: ReactElement; title: string; isPublic?: boolean };
31
type RouteConfigs = Record<string, RouteConfig>;
32

33
export const routeConfigs: RouteConfigs = {
3✔
34
  auditlog: { path: 'auditlog', element: <AuditLogs />, title: 'Audit log' },
35
  dashboard: { path: '', element: <Dashboard />, title: 'Dashboard' },
36
  deployments: { path: 'deployments', element: <Deployments />, title: 'Deployments' },
37
  devices: { path: 'devices', element: <Devices />, title: 'Devices' },
38
  help: { path: 'help', element: <Help />, title: 'Help & support' },
39
  login: { path: 'login', element: <Login />, title: 'Tenants', isPublic: true },
40
  password: { path: 'password', element: <Password />, title: 'Tenants', isPublic: true },
41
  passwordReset: { path: 'password/:secretHash', element: <PasswordReset />, title: 'Tenants' },
42
  releases: { path: 'releases', element: <Releases />, title: 'Releases' },
43
  settings: { path: 'settings', element: <Settings />, title: 'Settings' },
44
  signup: { path: 'signup', element: <Signup />, title: 'Tenants', isPublic: true },
45
  tenants: { path: 'tenants', element: <TenantPage />, title: 'Tenants' }
46
};
47

48
const publicRoutes: string[] = Object.values(routeConfigs).reduce((accu, { path, isPublic }) => (isPublic ? [...accu, `/${path}`] : accu), [] as string[]);
36✔
49

50
const LocationValidator = () => {
3✔
51
  const location = useLocation();
17✔
52

53
  if (publicRoutes.some(publicRoute => location.pathname.startsWith(publicRoute))) {
51!
54
    window.location.replace('/ui/');
×
55
    return;
×
56
  }
57
  return <Outlet />;
17✔
58
};
59

60
export const PrivateRoutes = () => (
3✔
61
  <Routes>
17✔
62
    <Route element={<LocationValidator />}>
63
      <Route path={routeConfigs.auditlog.path} element={routeConfigs.auditlog.element} />
64
      <Route path={routeConfigs.devices.path} element={routeConfigs.devices.element}>
65
        <Route path=":status" element={null} />
66
      </Route>
67
      <Route path={routeConfigs.releases.path} element={routeConfigs.releases.element}>
68
        <Route path=":artifactVersion" element={null} />
69
      </Route>
70
      <Route path={routeConfigs.deployments.path} element={routeConfigs.deployments.element}>
71
        <Route path=":tab" element={null} />
72
      </Route>
73
      <Route path={routeConfigs.settings.path} element={routeConfigs.settings.element}>
74
        <Route path=":section" element={null} />
75
      </Route>
76
      <Route path={routeConfigs.help.path} element={routeConfigs.help.element}>
77
        <Route path=":section" element={null} />
78
      </Route>
79
      <Route path="*" element={routeConfigs.dashboard.element} />
80
    </Route>
81
  </Routes>
82
);
83

84
export const PrivateSPRoutes = () => (
3✔
NEW
85
  <Routes>
×
86
    <Route element={<LocationValidator />}>
87
      <Route path={routeConfigs.auditlog.path} element={routeConfigs.auditlog.element} />
88
      <Route path={routeConfigs.settings.path} element={routeConfigs.settings.element}>
89
        <Route path=":section" element={null} />
90
      </Route>
91
      <Route path={routeConfigs.help.path} element={routeConfigs.help.element}>
92
        <Route path=":section" element={null} />
93
      </Route>
94
      <Route path={routeConfigs.tenants.path} element={routeConfigs.tenants.element}>
95
        <Route path=":tenantId" element={null} />
96
      </Route>
97
      <Route path="*" element={<Navigate to={routeConfigs.tenants.path} replace />} />
98
    </Route>
99
  </Routes>
100
);
101

102
export const PublicRoutes = () => (
3✔
103
  <Routes>
6✔
104
    <Route path={routeConfigs.password.path} element={routeConfigs.password.element} />
105
    <Route path={routeConfigs.passwordReset.path} element={routeConfigs.passwordReset.element} />
106
    <Route path={routeConfigs.signup.path} element={routeConfigs.signup.element}>
107
      <Route path=":campaign" element={null} />
108
    </Route>
109
    <Route path="*" element={routeConfigs.login.element} />
110
  </Routes>
111
);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc