Skip to content

Commit b579cdb

Browse files
committed
Merge stage for release 1.2.0
2 parents 12867fc + 0540b11 commit b579cdb

File tree

143 files changed

+4132
-902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4132
-902
lines changed

ormconfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = {
77
"database": "os2iot",
88
"synchronize": false,
99
"logging": false,
10-
"entities": ["src/entities/*.ts"],
10+
"entities": ["src/entities/*.ts", "src/entities/permissions/*.ts"],
1111
"migrations": ["src/migration/*.ts"],
1212
"cli": {
1313
"migrationsDir": "src/migration"

package-lock.json

Lines changed: 101 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@
5858
"mqtt": "^4.2.6",
5959
"nestjs-pino": "^1.3.0",
6060
"njwt": "^1.0.0",
61+
"nodemailer": "^6.7.2",
6162
"passport": "^0.4.1",
6263
"passport-headerapikey": "^1.2.2",
6364
"passport-jwt": "^4.0.0",
6465
"passport-local": "^1.0.0",
6566
"passport-saml": "^1.3.5",
6667
"pg": "^8.5.1",
68+
"protobufjs": "^6.11.2",
6769
"reflect-metadata": "^0.1.13",
6870
"rimraf": "^3.0.2",
6971
"rxjs": "^6.6.3",
@@ -83,6 +85,7 @@
8385
"@types/express": "^4.17.9",
8486
"@types/lodash": "^4.14.165",
8587
"@types/node": "^14.14.14",
88+
"@types/nodemailer": "^6.4.4",
8689
"@types/passport-jwt": "^3.0.3",
8790
"@types/passport-local": "^1.0.33",
8891
"@types/supertest": "^2.0.10",

resources/chirpstack-state.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
package gw;
4+
5+
// ConnState contains the connection state of a gateway.
6+
message ConnState {
7+
// Gateway ID.
8+
bytes gateway_id = 1 [json_name = "gatewayID"];
9+
10+
enum State {
11+
OFFLINE = 0;
12+
ONLINE = 1;
13+
}
14+
15+
State state = 2;
16+
}

src/auth/roles.decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SetMetadata } from "@nestjs/common";
44
import { RolesMetaData } from "./constants";
55

66
export const Read = () => SetMetadata(RolesMetaData, PermissionType.Read);
7-
export const Write = () => SetMetadata(RolesMetaData, PermissionType.Write);
8-
export const OrganizationAdmin = () =>
9-
SetMetadata(RolesMetaData, PermissionType.OrganizationAdmin);
7+
export const UserAdmin = () => SetMetadata(RolesMetaData, PermissionType.OrganizationUserAdmin);
8+
export const GatewayAdmin = () => SetMetadata(RolesMetaData, PermissionType.OrganizationGatewayAdmin);
9+
export const ApplicationAdmin = () => SetMetadata(RolesMetaData, PermissionType.OrganizationApplicationAdmin);
1010
export const GlobalAdmin = () => SetMetadata(RolesMetaData, PermissionType.GlobalAdmin);

src/auth/roles.guard.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,37 @@ export class RolesGuard implements CanActivate {
4040
hasAccess(user: AuthenticatedUser, roleRequired: string): boolean {
4141
if (user.permissions.isGlobalAdmin) {
4242
return true;
43-
} else if (roleRequired == PermissionType.OrganizationAdmin) {
44-
return this.hasOrganizationAdminAccess(user);
45-
} else if (roleRequired == PermissionType.Write) {
46-
return this.hasOrganizationAdminAccess(user) || this.hasWriteAccess(user);
43+
} else if (roleRequired == PermissionType.OrganizationApplicationAdmin) {
44+
return this.hasOrganizationApplicationAdminAccess(user);
45+
} else if (roleRequired == PermissionType.OrganizationUserAdmin) {
46+
return this.hasOrganizationUserAdminAccess(user);
47+
} else if (roleRequired == PermissionType.OrganizationGatewayAdmin) {
48+
return this.hasOrganizationGatewayAdminAccess(user);
4749
} else if (roleRequired == PermissionType.Read) {
4850
return (
49-
this.hasOrganizationAdminAccess(user) ||
50-
this.hasWriteAccess(user) ||
51+
this.hasOrganizationApplicationAdminAccess(user) ||
52+
this.hasOrganizationUserAdminAccess(user) ||
53+
this.hasOrganizationGatewayAdminAccess(user) ||
5154
this.hasReadAccess(user)
5255
);
5356
}
5457

5558
return false;
5659
}
5760

58-
hasOrganizationAdminAccess(user: AuthenticatedUser): boolean {
59-
return user.permissions.organizationAdminPermissions.size > 0;
61+
hasOrganizationApplicationAdminAccess(user: AuthenticatedUser): boolean {
62+
return user.permissions.orgToApplicationAdminPermissions.size > 0;
6063
}
6164

62-
hasWriteAccess(user: AuthenticatedUser): boolean {
63-
return this.hasSomeAccess(user.permissions.writePermissions);
65+
hasOrganizationUserAdminAccess(user: AuthenticatedUser): boolean {
66+
return user.permissions.orgToUserAdminPermissions.size > 0;
6467
}
6568

66-
hasReadAccess(user: AuthenticatedUser): boolean {
67-
return this.hasSomeAccess(user.permissions.readPermissions);
69+
hasOrganizationGatewayAdminAccess(user: AuthenticatedUser): boolean {
70+
return user.permissions.orgToGatewayAdminPermissions.size > 0;
6871
}
6972

70-
hasSomeAccess(userPermission: Map<number, number[]>): boolean {
71-
return userPermission.size > 0;
73+
hasReadAccess(user: AuthenticatedUser): boolean {
74+
return user.permissions.orgToReadPermissions.size > 0;
7275
}
7376
}

src/config/configuration.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GetLogLevels } from "@helpers/env-variable-helper";
1+
import { GetLogLevels, formatEmail } from "@helpers/env-variable-helper";
22

33
export default (): any => {
44
return {
@@ -8,7 +8,7 @@ export default (): any => {
88
port: parseInt(process.env.DATABASE_PORT, 10) || 5433,
99
username: process.env.DATABASE_USERNAME || "os2iot",
1010
password: process.env.DATABASE_PASSWORD || "toi2so",
11-
ssl: process.env.DATABASE_ENABLE_SSL === "true"
11+
ssl: process.env.DATABASE_ENABLE_SSL === "true",
1212
},
1313
jwt: {
1414
secret: process.env.JWT_SECRET || "secretKey-os2iot-secretKey",
@@ -17,6 +17,8 @@ export default (): any => {
1717
backend: {
1818
baseurl:
1919
process.env.BACKEND_BASEURL || "https://test-os2iot-backend.os2iot.dk",
20+
deviceStatsIntervalInDays:
21+
parseInt(process.env.DEVICE_STATS_INTERVAL_IN_DAYS, 10) || 29,
2022
},
2123
kombit: {
2224
entryPoint:
@@ -30,6 +32,24 @@ export default (): any => {
3032
chirpstack: {
3133
jwtsecret: process.env.CHIRPSTACK_JWTSECRET || "verysecret",
3234
},
33-
logLevels: process.env.LOG_LEVEL ? GetLogLevels(process.env.LOG_LEVEL) : GetLogLevels('debug')
35+
logLevels: process.env.LOG_LEVEL
36+
? GetLogLevels(process.env.LOG_LEVEL)
37+
: GetLogLevels("debug"),
38+
email: {
39+
host: process.env.EMAIL_HOST || "smtp.ethereal.email",
40+
port: process.env.EMAIL_PORT || 587,
41+
user: process.env.EMAIL_USER || "[email protected]",
42+
pass: process.env.EMAIL_PASS || "KzRSyYReEygpFPPZdd",
43+
/**
44+
* Can be formatted to show a user-friendly name before the e-mail.
45+
* E.g. "OS2iot <[email protected]>"
46+
*/
47+
from: process.env.EMAIL_FROM
48+
? formatEmail(process.env.EMAIL_FROM)
49+
: "OS2iot [email protected]",
50+
},
51+
frontend: {
52+
baseurl: process.env.FRONTEND_BASEURL || "http://localhost:8081",
53+
},
3454
};
3555
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const MqttClientId = "os2iot-backend";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const DefaultLimit = 100;
2+
export const DefaultOffset = 0;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// OS2iot won't be translated in any other language than Danish in the foreseeable future
2+
export enum Translations {
3+
OrganizationAdmin = "Organisationsadministrator",
4+
ApplicationAdmin = "Applikationsadministrator",
5+
ReadLevel = "Læserettigheder",
6+
}

0 commit comments

Comments
 (0)