XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: per-component decorator permissions (#3476)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3476 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

6587866e
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

8 个文件 +52 -27
Modified src/controllers/api/abortDojoComponentController.ts +9 -7
@@ -3,6 +3,7 @@ import {
3 3 getGuildForRequestEx,
4 4 hasAccessToDojo,
5 5 hasGuildPermission,
6 hasPermissionToDecorateComponent,
6 7 removeDojoDeco,
7 8 removeDojoRoom
8 9 } from "../../services/guildService.ts";
@@ -30,18 +31,19 @@ const abortDojoComponent = async (
30 31 const inventory = await getInventory(accountId, "GuildId LevelKeys");
31 32 const guild = await getGuildForRequestEx(req, inventory);
32 33
33 if (
34 !hasAccessToDojo(inventory) ||
35 !(await hasGuildPermission(guild, accountId, decoId ? GuildPermission.Decorator : GuildPermission.Architect))
36 ) {
37 return { DojoRequestStatus: -1 };
38 }
39
40 34 if (decoId) {
35 if (!hasAccessToDojo(inventory) || !(await hasPermissionToDecorateComponent(guild, accountId, componentId))) {
36 return { DojoRequestStatus: -1 };
37 }
38
41 39 removeDojoDeco(guild, componentId, decoId);
42 40 await guild.save();
43 41 return await getDojoClient(guild, 0, componentId, account.BuildLabel);
44 42 } else {
43 if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Architect))) {
44 return { DojoRequestStatus: -1 };
45 }
46
45 47 await removeDojoRoom(guild, componentId);
46 48 await guild.save();
47 49 return await getDojoClient(guild, 0, undefined, account.BuildLabel);
Modified src/controllers/api/destroyDojoDecoController.ts +6 -4
@@ -2,13 +2,12 @@ import {
2 2 getDojoClient,
3 3 getGuildForRequestEx,
4 4 hasAccessToDojo,
5 hasGuildPermission,
5 hasPermissionToDecorateComponent,
6 6 refundDojoDeco,
7 7 removeDojoDeco
8 8 } from "../../services/guildService.ts";
9 9 import { getInventory } from "../../services/inventoryService.ts";
10 10 import { getAccountIdForRequest } from "../../services/loginService.ts";
11 import { GuildPermission } from "../../types/guildTypes.ts";
12 11 import { logger } from "../../utils/logger.ts";
13 12 import type { RequestHandler } from "express";
14 13
@@ -16,11 +15,14 @@ export const destroyDojoDecoController: RequestHandler = async (req, res) => {
16 15 const accountId = await getAccountIdForRequest(req);
17 16 const inventory = await getInventory(accountId, "GuildId LevelKeys");
18 17 const guild = await getGuildForRequestEx(req, inventory);
19 if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Decorator))) {
18 const request = JSON.parse(String(req.body)) as IDestroyDojoDecoRequest | IClearObstacleCourseRequest;
19 if (
20 !hasAccessToDojo(inventory) ||
21 !(await hasPermissionToDecorateComponent(guild, accountId, request.ComponentId))
22 ) {
20 23 res.json({ DojoRequestStatus: -1 });
21 24 return;
22 25 }
23 const request = JSON.parse(String(req.body)) as IDestroyDojoDecoRequest | IClearObstacleCourseRequest;
24 26 if ("DecoType" in request) {
25 27 removeDojoDeco(guild, request.ComponentId, request.DecoId);
26 28 } else if (request.Act == "cObst") {
Modified src/controllers/api/placeDecoInComponentController.ts +5 -5
@@ -3,13 +3,12 @@ import {
3 3 getGuildForRequestEx,
4 4 getVaultMiscItemCount,
5 5 hasAccessToDojo,
6 hasGuildPermission,
6 hasPermissionToDecorateComponent,
7 7 processDojoBuildMaterialsGathered,
8 8 scaleRequiredCount
9 9 } from "../../services/guildService.ts";
10 10 import { getInventory } from "../../services/inventoryService.ts";
11 11 import { getAccountForRequest } from "../../services/loginService.ts";
12 import { GuildPermission } from "../../types/guildTypes.ts";
13 12 import type { RequestHandler } from "express";
14 13 import { Types } from "mongoose";
15 14 import { ExportDojoRecipes, ExportResources } from "warframe-public-export-plus";
@@ -19,12 +18,13 @@ export const placeDecoInComponentController: RequestHandler = async (req, res) =
19 18 const accountId = account._id.toString();
20 19 const inventory = await getInventory(accountId, "GuildId LevelKeys");
21 20 const guild = await getGuildForRequestEx(req, inventory);
22 if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Decorator))) {
21 const request = JSON.parse(String(req.body)) as IPlaceDecoInComponentRequest;
22 const componentId = request.ComponentId ?? (req.query.componentId as string);
23 if (!hasAccessToDojo(inventory) || !(await hasPermissionToDecorateComponent(guild, accountId, componentId))) {
23 24 res.json({ DojoRequestStatus: -1 });
24 25 return;
25 26 }
26 const request = JSON.parse(String(req.body)) as IPlaceDecoInComponentRequest;
27 const component = guild.DojoComponents.id(request.ComponentId ?? (req.query.componentId as string))!;
27 const component = guild.DojoComponents.id(componentId)!;
28 28
29 29 if (component.DecoCapacity === undefined) {
30 30 component.DecoCapacity = Object.values(ExportDojoRecipes.rooms).find(
Modified src/controllers/api/setDojoComponentColorsController.ts +3 -4
@@ -3,22 +3,21 @@ import {
3 3 getDojoClient,
4 4 getGuildForRequestEx,
5 5 hasAccessToDojo,
6 hasGuildPermission
6 hasPermissionToDecorateComponent
7 7 } from "../../services/guildService.ts";
8 8 import { getInventory } from "../../services/inventoryService.ts";
9 9 import { getAccountIdForRequest } from "../../services/loginService.ts";
10 import { GuildPermission } from "../../types/guildTypes.ts";
11 10 import type { RequestHandler } from "express";
12 11
13 12 export const setDojoComponentColorsController: RequestHandler = async (req, res) => {
14 13 const accountId = await getAccountIdForRequest(req);
15 14 const inventory = await getInventory(accountId, "GuildId LevelKeys");
16 15 const guild = await getGuildForRequestEx(req, inventory);
17 if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Decorator))) {
16 const data = getJSONfromString<ISetDojoComponentColorsRequest>(String(req.body));
17 if (!hasAccessToDojo(inventory) || !(await hasPermissionToDecorateComponent(guild, accountId, data.ComponentId))) {
18 18 res.json({ DojoRequestStatus: -1 });
19 19 return;
20 20 }
21 const data = getJSONfromString<ISetDojoComponentColorsRequest>(String(req.body));
22 21 const component = guild.DojoComponents.id(data.ComponentId)!;
23 22 //const deco = component.Decos!.find(x => x._id.equals(data.DecoId))!;
24 23 //deco.Pending = true;
Modified src/controllers/api/setDojoComponentSettingsController.ts +4 -4
@@ -3,22 +3,22 @@ import {
3 3 getDojoClient,
4 4 getGuildForRequestEx,
5 5 hasAccessToDojo,
6 hasGuildPermission
6 hasPermissionToDecorateComponent
7 7 } from "../../services/guildService.ts";
8 8 import { getInventory } from "../../services/inventoryService.ts";
9 9 import { getAccountIdForRequest } from "../../services/loginService.ts";
10 import { GuildPermission } from "../../types/guildTypes.ts";
11 10 import type { RequestHandler } from "express";
12 11
13 12 export const setDojoComponentSettingsController: RequestHandler = async (req, res) => {
14 13 const accountId = await getAccountIdForRequest(req);
15 14 const inventory = await getInventory(accountId, "GuildId LevelKeys");
16 15 const guild = await getGuildForRequestEx(req, inventory);
17 if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Decorator))) {
16 const componentId = req.query.componentId as string;
17 if (!hasAccessToDojo(inventory) || !(await hasPermissionToDecorateComponent(guild, accountId, componentId))) {
18 18 res.json({ DojoRequestStatus: -1 });
19 19 return;
20 20 }
21 const component = guild.DojoComponents.id(req.query.componentId as string)!;
21 const component = guild.DojoComponents.id(componentId)!;
22 22 const data = getJSONfromString<ISetDojoComponentSettingsRequest>(String(req.body));
23 23 component.Settings = data.Settings;
24 24 await guild.save();
Modified src/services/guildService.ts +19 -0
@@ -12,6 +12,7 @@ import type {
12 12 IDojoClient,
13 13 IDojoComponentClient,
14 14 IDojoComponentDatabase,
15 IDojoComponentSettings,
15 16 IDojoContributable,
16 17 IDojoDecoClient,
17 18 IDojoDecoDatabase,
@@ -523,6 +524,24 @@ export const hasGuildPermission = async (
523 524 return false;
524 525 };
525 526
527 export const hasPermissionToDecorateComponent = async (
528 guild: TGuildDatabaseDocument,
529 accountId: string,
530 componentId: string | Types.ObjectId
531 ): Promise<boolean> => {
532 if (await hasGuildPermission(guild, accountId, GuildPermission.Decorator)) {
533 return true;
534 }
535 const component = guild.DojoComponents.id(componentId);
536 if (component?.Settings) {
537 const settings = JSON.parse(component.Settings) as IDojoComponentSettings;
538 if (settings.decorators && settings.decorators.indexOf(accountId) != -1) {
539 return true;
540 }
541 }
542 return false;
543 };
544
526 545 export const hasGuildPermissionEx = (
527 546 guild: TGuildDatabaseDocument,
528 547 member: IGuildMemberDatabase,
Modified src/services/shipCustomizationsService.ts +2 -3
@@ -15,8 +15,7 @@ import { logger } from "../utils/logger.ts";
15 15 import { Types } from "mongoose";
16 16 import { addFusionTreasures, addShipDecorations, getInventory } from "./inventoryService.ts";
17 17 import { Guild } from "../models/guildModel.ts";
18 import { hasGuildPermission } from "./guildService.ts";
19 import { GuildPermission } from "../types/guildTypes.ts";
18 import { hasPermissionToDecorateComponent } from "./guildService.ts";
20 19 import { ExportResources } from "warframe-public-export-plus";
21 20 import { convertCustomizationInfo } from "./importService.ts";
22 21
@@ -241,7 +240,7 @@ export const handleResetShipDecorations = async (
241 240 export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise<void> => {
242 241 if (req.GuildId && req.ComponentId) {
243 242 const guild = (await Guild.findById(req.GuildId))!;
244 if (await hasGuildPermission(guild, accountId, GuildPermission.Decorator)) {
243 if (await hasPermissionToDecorateComponent(guild, accountId, req.ComponentId)) {
245 244 const component = guild.DojoComponents.id(req.ComponentId)!;
246 245 const deco = component.Decos!.find(x => x._id.equals(req.DecoId))!;
247 246 deco.PictureFrameInfo = req.PictureFrameInfo;
Modified src/types/guildTypes.ts +4 -0
@@ -194,6 +194,10 @@ export interface IDojoComponentClient {
194 194 Settings?: string;
195 195 }
196 196
197 export interface IDojoComponentSettings {
198 decorators?: string[];
199 }
200
197 201 export interface IDojoComponentDatabase extends Omit<
198 202 IDojoComponentClient,
199 203 "id" | "SortId" | "pi" | "CompletionTime" | "DestructionTime" | "Decos" | "PaintBot"