source: TFP-WebServer/WebServer/src/WebAPI/APIs/Permissions/PermissionsApiHelpers.cs@ 473

Last change on this file since 473 was 434, checked in by alloc, 19 months ago

Added permission management APIs

File size: 1.4 KB
Line 
1using System;
2using System.Net;
3
4namespace Webserver.WebAPI.APIs.Permissions {
5 public static class PermissionsApiHelpers {
6 public static bool TryParseId (RequestContext _context, byte[] _jsonInputData, out PlatformUserIdentifierAbs _userId,
7 out string _groupId) {
8 string id = _context.RequestPath;
9 _userId = default;
10 _groupId = default;
11
12 if (string.IsNullOrEmpty (id)) {
13 WebUtils.SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_USER_OR_GROUP");
14 return false;
15 }
16
17 const string kindUserPrefix = "user/";
18 if (id.StartsWith (kindUserPrefix, StringComparison.Ordinal)) {
19 bool validId = PlatformUserIdentifierAbs.TryFromCombinedString (id.Substring (kindUserPrefix.Length), out _userId);
20 if (!validId) {
21 WebUtils.SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_USER");
22 }
23
24 return validId;
25 }
26
27 const string kindGroupPrefix = "group/";
28 if (id.StartsWith (kindGroupPrefix, StringComparison.Ordinal)) {
29 _groupId = id.Substring (kindGroupPrefix.Length);
30 bool validId = _groupId.Length > 0;
31 if (!validId) {
32 WebUtils.SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_GROUP");
33 }
34
35 return validId;
36 }
37
38 WebUtils.SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_KIND");
39 return false;
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.