@steedos/accounts 2.7.27-beta.6 → 3.0.0-beta.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/index.js +66 -26
- package/lib/core/index.js.map +1 -1
- package/lib/database-mongo/mongo.js +5 -5
- package/lib/database-mongo/mongo.js.map +1 -1
- package/lib/index.js +5 -5
- package/lib/index.js.map +1 -1
- package/lib/mail.js +44 -46
- package/lib/mail.js.map +1 -1
- package/lib/password/accounts-password.js +6 -6
- package/lib/password/accounts-password.js.map +1 -1
- package/lib/password/utils/encryption.js.map +1 -1
- package/lib/rest-express/endpoints/authorize.js +49 -38
- package/lib/rest-express/endpoints/authorize.js.map +1 -1
- package/lib/rest-express/endpoints/geetestV3/geetest-init.js.map +1 -1
- package/lib/rest-express/endpoints/geetestV3/sdk/geetest_lib.js.map +1 -1
- package/lib/rest-express/endpoints/initServer.js.map +1 -1
- package/lib/rest-express/endpoints/login.js.map +1 -1
- package/lib/rest-express/endpoints/logout.js +79 -72
- package/lib/rest-express/endpoints/logout.js.map +1 -1
- package/lib/rest-express/endpoints/oauth/provider-callback.js.map +1 -1
- package/lib/rest-express/endpoints/password/change-password.js +94 -89
- package/lib/rest-express/endpoints/password/change-password.js.map +1 -1
- package/lib/rest-express/endpoints/password/register.js.map +1 -1
- package/lib/rest-express/endpoints/password/setSpaceUserPassword.js +152 -0
- package/lib/rest-express/endpoints/password/setSpaceUserPassword.js.map +1 -0
- package/lib/rest-express/endpoints/password/two-factor.js.map +1 -1
- package/lib/rest-express/endpoints/password/verify.js.map +1 -1
- package/lib/rest-express/endpoints/put-user-name.js.map +1 -1
- package/lib/rest-express/endpoints/service-authenticate.js.map +1 -1
- package/lib/rest-express/endpoints/spaces.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/accept_invitation.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/create-tenant.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/decline_invitation.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/get-tenant.js +62 -39
- package/lib/rest-express/endpoints/steedos/get-tenant.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/settings.js +119 -88
- package/lib/rest-express/endpoints/steedos/settings.js.map +1 -1
- package/lib/rest-express/endpoints/update-session.js.map +1 -1
- package/lib/rest-express/express-middleware.js +2 -0
- package/lib/rest-express/express-middleware.js.map +1 -1
- package/lib/rest-express/user-loader.js +82 -67
- package/lib/rest-express/user-loader.js.map +1 -1
- package/lib/rest-express/utils/get-user-agent.js.map +1 -1
- package/lib/rest-express/utils/users.js.map +1 -1
- package/lib/server/accounts-server.js +3 -3
- package/lib/server/accounts-server.js.map +1 -1
- package/lib/server/utils/get-first-user-email.js +1 -2
- package/lib/server/utils/get-first-user-email.js.map +1 -1
- package/lib/server/utils/tokens.js.map +1 -1
- package/package.json +5 -16
- package/package.service.js +10 -6
- package/src/core/index.ts +201 -141
- package/src/database-mongo/mongo.ts +1 -1
- package/src/rest-express/endpoints/authorize.ts +58 -48
- package/src/rest-express/endpoints/logout.ts +74 -72
- package/src/rest-express/endpoints/password/change-password.ts +92 -81
- package/src/rest-express/endpoints/password/setSpaceUserPassword.ts +127 -0
- package/src/rest-express/endpoints/steedos/get-tenant.ts +56 -38
- package/src/rest-express/endpoints/steedos/settings.ts +118 -89
- package/src/rest-express/express-middleware.ts +7 -0
- package/src/rest-express/user-loader.ts +68 -58
- package/plugin.config.yml +0 -4
|
@@ -3,80 +3,82 @@
|
|
|
3
3
|
* @Date: 2022-03-28 09:35:34
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
5
|
* @LastEditTime: 2024-01-23 14:24:35
|
|
6
|
-
* @Description:
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
import * as express from
|
|
9
|
-
import { get, isEmpty, map } from
|
|
10
|
-
import { AccountsServer } from
|
|
11
|
-
import { sendError } from
|
|
12
|
-
import { clearAuthCookies } from
|
|
13
|
-
import { getObject } from
|
|
14
|
-
import * as requestIp from
|
|
15
|
-
import { getUserAgent } from
|
|
16
|
-
import isMobile from
|
|
17
|
-
import { getSteedosSchema } from
|
|
18
|
-
export const logout =
|
|
19
|
-
|
|
20
|
-
res: express.Response
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
get(req.headers, 'Authorization') ||
|
|
26
|
-
get(req.headers, 'authorization');
|
|
8
|
+
import * as express from "express";
|
|
9
|
+
import { get, isEmpty, map } from "lodash";
|
|
10
|
+
import { AccountsServer } from "../../server";
|
|
11
|
+
import { sendError } from "../utils/send-error";
|
|
12
|
+
import { clearAuthCookies } from "../utils/steedos-auth";
|
|
13
|
+
import { getObject } from "@steedos/objectql";
|
|
14
|
+
import * as requestIp from "request-ip";
|
|
15
|
+
import { getUserAgent } from "../utils/get-user-agent";
|
|
16
|
+
import isMobile from "ismobilejs";
|
|
17
|
+
import { getSteedosSchema } from "@steedos/objectql";
|
|
18
|
+
export const logout =
|
|
19
|
+
(accountsServer: AccountsServer) =>
|
|
20
|
+
async (req: express.Request, res: express.Response) => {
|
|
21
|
+
let authToken =
|
|
22
|
+
get(req.cookies, "X-Auth-Token") ||
|
|
23
|
+
get(req.headers, "Authorization") ||
|
|
24
|
+
get(req.headers, "authorization");
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
authToken = authToken && authToken.replace("Bearer ", "token");
|
|
27
|
+
authToken =
|
|
28
|
+
authToken && authToken.split(",").length > 1
|
|
29
|
+
? authToken.split(",")[0]
|
|
30
|
+
: authToken;
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
32
|
+
clearAuthCookies(req, res);
|
|
33
|
+
let session = null;
|
|
34
|
+
try {
|
|
35
|
+
session = await accountsServer.logout(authToken);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
//sendError(res, err);
|
|
38
|
+
} finally {
|
|
39
|
+
let userAgent = getUserAgent(req) || "";
|
|
40
|
+
const ip = requestIp.getClientIp(req);
|
|
41
|
+
let status = "success";
|
|
42
|
+
let message = "";
|
|
43
|
+
let is_phone = false;
|
|
44
|
+
let is_tablet = false;
|
|
45
|
+
if (userAgent) {
|
|
46
|
+
try {
|
|
47
|
+
const { phone, tablet } = isMobile(userAgent);
|
|
48
|
+
is_phone = phone;
|
|
49
|
+
is_tablet = tablet;
|
|
50
|
+
} catch (Exception) {
|
|
51
|
+
console.log(`Exception`, Exception);
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
await getObject("operation_logs").insert({
|
|
55
|
+
name: "注销",
|
|
56
|
+
type: "logout",
|
|
57
|
+
remote_user: session?.userId,
|
|
58
|
+
remote_addr: ip,
|
|
59
|
+
http_user_agent: userAgent,
|
|
60
|
+
is_mobile: is_phone,
|
|
61
|
+
is_tablet,
|
|
62
|
+
object: "users",
|
|
63
|
+
status: status,
|
|
64
|
+
create: new Date(),
|
|
65
|
+
space: session?.space,
|
|
66
|
+
message: message,
|
|
67
|
+
data: JSON.stringify({
|
|
68
|
+
authToken: authToken,
|
|
69
|
+
session: session,
|
|
70
|
+
}),
|
|
71
|
+
related_to: {
|
|
72
|
+
o: "users",
|
|
73
|
+
ids: [session?.userId],
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
if (authToken) {
|
|
77
|
+
const broker = getSteedosSchema().broker;
|
|
78
|
+
broker.broadcast("$user.logout", {
|
|
79
|
+
authToken: authToken,
|
|
80
|
+
});
|
|
73
81
|
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
broker.broadcast("$user.logout", {
|
|
78
|
-
authToken: authToken
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
res.json(null);
|
|
82
|
-
};
|
|
82
|
+
}
|
|
83
|
+
res.json(null);
|
|
84
|
+
};
|
|
@@ -3,101 +3,112 @@
|
|
|
3
3
|
* @Date: 2022-05-19 11:38:30
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
5
|
* @LastEditTime: 2023-09-18 17:58:22
|
|
6
|
-
* @Description:
|
|
6
|
+
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
import * as express from
|
|
9
|
-
import { AccountsServer } from
|
|
10
|
-
import { sendError } from
|
|
11
|
-
import { getSteedosConfig, getObject } from
|
|
12
|
-
import { hashPassword } from
|
|
8
|
+
import * as express from "express";
|
|
9
|
+
import { AccountsServer } from "../../../server";
|
|
10
|
+
import { sendError } from "../../utils/send-error";
|
|
11
|
+
import { getSteedosConfig, getObject } from "@steedos/objectql";
|
|
12
|
+
import { hashPassword } from "../../../password/utils";
|
|
13
13
|
|
|
14
|
-
import * as requestIp from
|
|
15
|
-
import { getUserAgent } from
|
|
14
|
+
import * as requestIp from "request-ip";
|
|
15
|
+
import { getUserAgent } from "../../utils/get-user-agent";
|
|
16
16
|
import isMobile from "ismobilejs";
|
|
17
|
-
import { db } from
|
|
17
|
+
import { db } from "../../../db";
|
|
18
18
|
|
|
19
19
|
const config = getSteedosConfig();
|
|
20
20
|
declare var Creator;
|
|
21
21
|
|
|
22
|
-
export const changePassword =
|
|
23
|
-
|
|
24
|
-
res: express.Response
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const { oldPassword, newPassword } = req.body;
|
|
22
|
+
export const changePassword =
|
|
23
|
+
(accountsServer: AccountsServer) =>
|
|
24
|
+
async (req: express.Request, res: express.Response) => {
|
|
25
|
+
try {
|
|
26
|
+
if (!(req as any).userId) {
|
|
27
|
+
res.status(401);
|
|
28
|
+
res.json({ message: "Unauthorized" });
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
// oldPassword 、newPassword 已经是 sha256之后的
|
|
32
|
+
const { oldPassword, newPassword } = req.body;
|
|
34
33
|
|
|
35
|
-
|
|
34
|
+
// let passworPolicy = ((config as any).password || {}).policy
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const password: any = accountsServer.getServices().password;
|
|
36
|
+
// if(passworPolicy){
|
|
37
|
+
// if(!(new RegExp(passworPolicy)).test(newPassword || '')){
|
|
38
|
+
// sendError(res, new Error((config as any).password.policyError));
|
|
39
|
+
// return;
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
43
|
+
const password: any = accountsServer.getServices().password;
|
|
44
|
+
|
|
45
|
+
await password.changePassword(
|
|
46
|
+
(req as any).userId,
|
|
47
|
+
oldPassword,
|
|
48
|
+
newPassword,
|
|
49
|
+
);
|
|
50
|
+
password.db.collection.updateOne(
|
|
51
|
+
{ _id: (req as any).userId },
|
|
52
|
+
{ $set: { password_expired: false } },
|
|
53
|
+
);
|
|
54
|
+
try {
|
|
55
|
+
await db.updateMany(
|
|
56
|
+
"space_users",
|
|
57
|
+
[["user", "=", (req as any).userId]],
|
|
58
|
+
{ password_expired: false },
|
|
59
|
+
);
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
const userAgent = getUserAgent(req);
|
|
62
|
+
const ip = requestIp.getClientIp(req);
|
|
63
|
+
let is_phone = false;
|
|
64
|
+
let is_tablet = false;
|
|
65
|
+
if (userAgent) {
|
|
66
|
+
try {
|
|
67
|
+
const { phone, tablet } = isMobile(userAgent);
|
|
68
|
+
is_phone = phone;
|
|
69
|
+
is_tablet = tablet;
|
|
70
|
+
} catch (Exception) {
|
|
71
|
+
console.log(`Exception`, Exception);
|
|
72
|
+
}
|
|
64
73
|
}
|
|
65
|
-
}
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
const userSpaces = await db.find("space_users", {
|
|
76
|
+
filters: [
|
|
77
|
+
["user", "=", (req as any).userId],
|
|
78
|
+
["user_accepted", "=", true],
|
|
79
|
+
],
|
|
80
|
+
fields: ["space"],
|
|
81
|
+
});
|
|
71
82
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
if (userSpaces && userSpaces.length > 0) {
|
|
84
|
+
for (let userSpace of userSpaces) {
|
|
85
|
+
const userId = (req as any).userId;
|
|
86
|
+
await getObject("operation_logs").insert({
|
|
87
|
+
name: "修改密码",
|
|
88
|
+
type: "change_password",
|
|
89
|
+
remote_user: userId,
|
|
90
|
+
remote_addr: ip,
|
|
91
|
+
http_user_agent: userAgent,
|
|
92
|
+
is_mobile: is_phone,
|
|
93
|
+
is_tablet,
|
|
94
|
+
object: "users",
|
|
95
|
+
status: "success",
|
|
96
|
+
create: new Date(),
|
|
97
|
+
create_by: userId,
|
|
98
|
+
modified_by: userId,
|
|
99
|
+
space: userSpace.space,
|
|
100
|
+
related_to: {
|
|
101
|
+
o: "users",
|
|
102
|
+
ids: [userId],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
94
106
|
}
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log("error", error);
|
|
95
109
|
}
|
|
96
|
-
|
|
97
|
-
|
|
110
|
+
res.json({ userId: (req as any).userId, password_expired: false });
|
|
111
|
+
} catch (err) {
|
|
112
|
+
sendError(res, err);
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
} catch (err) {
|
|
101
|
-
sendError(res, err);
|
|
102
|
-
}
|
|
103
|
-
};
|
|
114
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: baozhoutao@steedos.com
|
|
3
|
+
* @Date: 2022-05-19 11:38:30
|
|
4
|
+
* @LastEditors: 孙浩林 sunhaolin@steedos.com
|
|
5
|
+
* @LastEditTime: 2025-03-04 10:35:09
|
|
6
|
+
* @Description:
|
|
7
|
+
*/
|
|
8
|
+
import { t } from "@steedos/i18n";
|
|
9
|
+
import { getObject } from "@steedos/objectql";
|
|
10
|
+
import * as express from "express";
|
|
11
|
+
import * as _ from "lodash";
|
|
12
|
+
import { bcryptPassword } from "../../../password/utils";
|
|
13
|
+
import { AccountsServer } from "../../../server";
|
|
14
|
+
|
|
15
|
+
declare var SMSQueue;
|
|
16
|
+
|
|
17
|
+
export const setSpaceUserPassword =
|
|
18
|
+
(accountsServer: AccountsServer) =>
|
|
19
|
+
async (req: express.Request, res: express.Response) => {
|
|
20
|
+
const userSession = (req as any).user;
|
|
21
|
+
let { space_user_id, space_id, password } = req.body;
|
|
22
|
+
try {
|
|
23
|
+
if (!userSession) {
|
|
24
|
+
res.status(401);
|
|
25
|
+
res.json({ message: "Unauthorized" });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const spaceUser = await getObject("space_users").findOne(space_user_id);
|
|
29
|
+
const userId = userSession.userId;
|
|
30
|
+
let canEdit = spaceUser.user === userId;
|
|
31
|
+
if (!canEdit) {
|
|
32
|
+
const space = await getObject("spaces").findOne(space_id);
|
|
33
|
+
const isSpaceAdmin = space?.admins?.includes(userSession.userId);
|
|
34
|
+
canEdit = isSpaceAdmin;
|
|
35
|
+
}
|
|
36
|
+
const companyIds = spaceUser.company_ids;
|
|
37
|
+
if (!canEdit && companyIds && companyIds.length) {
|
|
38
|
+
const companys = await getObject("company").find({
|
|
39
|
+
filters: [
|
|
40
|
+
["_id", "in", companyIds],
|
|
41
|
+
["space", "=", space_id],
|
|
42
|
+
],
|
|
43
|
+
fields: ["admins"],
|
|
44
|
+
});
|
|
45
|
+
if (companys && companys.length) {
|
|
46
|
+
canEdit = _.some(companys, function (item) {
|
|
47
|
+
return item.admins && item.admins.indexOf(userId) > -1;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!canEdit) {
|
|
52
|
+
throw new Error("您没有权限修改该用户密码");
|
|
53
|
+
}
|
|
54
|
+
const user_id = spaceUser.user;
|
|
55
|
+
const userCP = await getObject("users").findOne(user_id);
|
|
56
|
+
if (
|
|
57
|
+
spaceUser.invite_state === "pending" ||
|
|
58
|
+
spaceUser.invite_state === "refused"
|
|
59
|
+
) {
|
|
60
|
+
throw new Error("该用户尚未同意加入该工作区,无法修改密码");
|
|
61
|
+
}
|
|
62
|
+
let logout = true;
|
|
63
|
+
if (userSession.userId === user_id) {
|
|
64
|
+
logout = false;
|
|
65
|
+
}
|
|
66
|
+
const bcryptedPassword = await bcryptPassword(password);
|
|
67
|
+
const servicePassword: any = accountsServer.getServices().password;
|
|
68
|
+
await servicePassword.db.setPassword(user_id, bcryptedPassword);
|
|
69
|
+
const changedUserInfo = await getObject("users").findOne(user_id);
|
|
70
|
+
if (changedUserInfo?.services?.password?.bcrypt) {
|
|
71
|
+
await getObject("users").update(user_id, {
|
|
72
|
+
$push: {
|
|
73
|
+
"services.password_history":
|
|
74
|
+
changedUserInfo.services.password.bcrypt,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (userCP.mobile && userCP.mobile_verified) {
|
|
79
|
+
let lang = "en";
|
|
80
|
+
if (userCP.locale === "zh-cn") {
|
|
81
|
+
lang = "zh-CN";
|
|
82
|
+
}
|
|
83
|
+
SMSQueue.send({
|
|
84
|
+
Format: "JSON",
|
|
85
|
+
Action: "SingleSendSms",
|
|
86
|
+
ParamString: "",
|
|
87
|
+
RecNum: userCP.mobile,
|
|
88
|
+
SignName: "华炎办公",
|
|
89
|
+
TemplateCode: "SMS_67200967",
|
|
90
|
+
msg: t("sms.change_password.template", {}, lang),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
await getObject("operation_logs").insert({
|
|
95
|
+
name: "修改密码",
|
|
96
|
+
type: "change_password",
|
|
97
|
+
remote_user: userId,
|
|
98
|
+
status: "success",
|
|
99
|
+
space: space_id,
|
|
100
|
+
message:
|
|
101
|
+
"[系统管理员]修改了用户[" +
|
|
102
|
+
(changedUserInfo != null ? changedUserInfo.name : void 0) +
|
|
103
|
+
"]的密码",
|
|
104
|
+
data: JSON.stringify({
|
|
105
|
+
changeUser: user_id,
|
|
106
|
+
}),
|
|
107
|
+
related_to: {
|
|
108
|
+
o: "users",
|
|
109
|
+
ids: [user_id],
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
} catch (e) {
|
|
113
|
+
console.error(e);
|
|
114
|
+
}
|
|
115
|
+
return res.json({
|
|
116
|
+
status: 0,
|
|
117
|
+
msg: "",
|
|
118
|
+
data: {},
|
|
119
|
+
});
|
|
120
|
+
} catch (e) {
|
|
121
|
+
return res.json({
|
|
122
|
+
status: -1,
|
|
123
|
+
msg: e.message,
|
|
124
|
+
data: {},
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
@@ -1,44 +1,62 @@
|
|
|
1
|
-
import * as express from
|
|
2
|
-
import { AccountsServer } from
|
|
3
|
-
import { sendError } from
|
|
4
|
-
import { getSteedosConfig } from
|
|
5
|
-
import { db } from
|
|
6
|
-
import {getSteedosService } from
|
|
1
|
+
import * as express from "express";
|
|
2
|
+
import { AccountsServer } from "../../../server";
|
|
3
|
+
import { sendError } from "../../utils/send-error";
|
|
4
|
+
import { getSteedosConfig } from "@steedos/objectql";
|
|
5
|
+
import { db } from "../../../db";
|
|
6
|
+
import { getSteedosService } from "../../../core";
|
|
7
7
|
|
|
8
|
-
export const getTenant =
|
|
9
|
-
|
|
10
|
-
res: express.Response
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export const getTenant =
|
|
9
|
+
(accountsServer: AccountsServer) =>
|
|
10
|
+
async (req: express.Request, res: express.Response) => {
|
|
11
|
+
try {
|
|
12
|
+
const spaceId = req.params.id;
|
|
13
|
+
if (!spaceId) throw new Error("accounts.tenant_id_required");
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const spaceDoc = await db.findOne("spaces", spaceId, {
|
|
16
|
+
fields: [
|
|
17
|
+
"name",
|
|
18
|
+
"avatar",
|
|
19
|
+
"avatar_dark",
|
|
20
|
+
"background",
|
|
21
|
+
"enable_register",
|
|
22
|
+
"account_logo",
|
|
23
|
+
],
|
|
23
24
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let steedosService = getSteedosService();
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
spaceDoc.
|
|
26
|
+
if (!spaceDoc) {
|
|
27
|
+
return res.send({
|
|
28
|
+
exists: false,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let steedosService = getSteedosService();
|
|
33
|
+
|
|
34
|
+
if (steedosService) {
|
|
35
|
+
if (spaceDoc.account_logo) {
|
|
36
|
+
spaceDoc.logo_url =
|
|
37
|
+
steedosService +
|
|
38
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
39
|
+
spaceDoc.account_logo;
|
|
40
|
+
} else if (spaceDoc.avatar_dark) {
|
|
41
|
+
spaceDoc.logo_url =
|
|
42
|
+
steedosService +
|
|
43
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
44
|
+
spaceDoc.avatar_dark;
|
|
45
|
+
} else if (spaceDoc.avatar) {
|
|
46
|
+
spaceDoc.logo_url =
|
|
47
|
+
steedosService +
|
|
48
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
49
|
+
spaceDoc.avatar;
|
|
50
|
+
}
|
|
51
|
+
if (spaceDoc.background) {
|
|
52
|
+
spaceDoc.background_url =
|
|
53
|
+
steedosService +
|
|
54
|
+
"api/v6/files/cfs.avatars.filerecord/" +
|
|
55
|
+
spaceDoc.background;
|
|
56
|
+
}
|
|
38
57
|
}
|
|
58
|
+
res.json(spaceDoc);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
sendError(res, err);
|
|
39
61
|
}
|
|
40
|
-
|
|
41
|
-
} catch (err) {
|
|
42
|
-
sendError(res, err);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
62
|
+
};
|