VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
usersController.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <oatpp/web/server/api/ApiController.hpp>
9 #include <oatpp/parser/json/mapping/ObjectMapper.hpp>
10 #include <oatpp/core/macro/codegen.hpp>
11 #include <oatpp/core/macro/component.hpp>
12 
13 #include OATPP_CODEGEN_BEGIN(ApiController)
14 
32 class DtUsersController : public oatpp::web::server::api::ApiController
33 {
34 public:
35  explicit DtUsersController(const std::shared_ptr<ObjectMapper>& objectMapper)
36  : oatpp::web::server::api::ApiController(objectMapper)
37  {
38  }
39 
40  ENDPOINT_INFO(getUsers)
41  {
42  info->summary = "List all users";
43  info->description =
44  "Returns every user in the database with their username, permission list, "
45  "and a boolean indicating whether a password is currently set. "
46  "Password hashes are never returned. "
47  "Requires the 'configure.read' permission.";
48  info->addTag("Configure");
49  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
50  info->addResponse<oatpp::String>(Status::CODE_401, "application/json");
51  info->addResponse<oatpp::String>(Status::CODE_403, "application/json");
52  }
53  ENDPOINT("GET", "/api/configure/users", getUsers,
54  REQUEST(std::shared_ptr<IncomingRequest>, request))
55  {
56  return handleGetUsers(request);
57  }
58 
59  ENDPOINT_INFO(addUser)
60  {
61  info->summary = "Add a new user";
62  info->description =
63  "Creates a new user entry. "
64  "Body fields: 'username' (required string), "
65  "'preset' (optional string — name of a permission preset from GET /api/configure/presets), "
66  "'permissions' (optional array of extra permission strings on top of the preset), "
67  "'password' (optional string — omit or leave empty to create an account with no password). "
68  "Either 'preset' or 'permissions' (or both) must be provided. "
69  "Requires the 'users.write' permission.";
70  info->addTag("Configure");
71  info->addConsumes<oatpp::String>("application/json");
72  info->addResponse<oatpp::String>(Status::CODE_201, "application/json");
73  info->addResponse<oatpp::String>(Status::CODE_400, "application/json");
74  info->addResponse<oatpp::String>(Status::CODE_409, "application/json");
75  }
76  ENDPOINT("POST", "/api/configure/users", addUser,
77  REQUEST(std::shared_ptr<IncomingRequest>, request))
78  {
79  return handleAddUser(request);
80  }
81 
82  ENDPOINT_INFO(deleteUser)
83  {
84  info->summary = "Remove a user";
85  info->description =
86  "Deletes the user with the given username. "
87  "A user may not delete their own account. "
88  "Requires the 'configure.write' permission.";
89  info->addTag("Configure");
90  info->pathParams["username"].description = "Username of the user to delete";
91  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
92  info->addResponse<oatpp::String>(Status::CODE_400, "application/json");
93  info->addResponse<oatpp::String>(Status::CODE_403, "application/json");
94  info->addResponse<oatpp::String>(Status::CODE_404, "application/json");
95  }
96  ENDPOINT("DELETE", "/api/configure/users/{username}", deleteUser,
97  PATH(String, username), REQUEST(std::shared_ptr<IncomingRequest>, request))
98  {
99  return handleDeleteUser(request, username);
100  }
101 
102  ENDPOINT_INFO(setUserPermissions)
103  {
104  info->summary = "Replace a user's extra permissions";
105  info->description =
106  "Replaces the extra permission list for the given user. "
107  "This updates only the permissions beyond any assigned preset — the preset is preserved. "
108  "Body: { \"permissions\": [\"roles.read\", ...] } "
109  "Requires the 'users.write' permission.";
110  info->addTag("Configure");
111  info->pathParams["username"].description = "Username of the user to update";
112  info->addConsumes<oatpp::String>("application/json");
113  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
114  info->addResponse<oatpp::String>(Status::CODE_400, "application/json");
115  info->addResponse<oatpp::String>(Status::CODE_404, "application/json");
116  }
117  ENDPOINT("PUT", "/api/configure/users/{username}/permissions", setUserPermissions,
118  PATH(String, username), REQUEST(std::shared_ptr<IncomingRequest>, request))
119  {
120  return handleSetUserPermissions(request, username);
121  }
122 
123  ENDPOINT_INFO(setUserPreset)
124  {
125  info->summary = "Set or clear a user's preset";
126  info->description =
127  "Sets the named preset for the given user. "
128  "Body: { \"preset\": \"admin\" } "
129  "Send an empty string to remove the preset assignment. "
130  "The user's extra permissions are not affected. "
131  "Requires the 'users.write' permission.";
132  info->addTag("Configure");
133  info->pathParams["username"].description = "Username of the user to update";
134  info->addConsumes<oatpp::String>("application/json");
135  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
136  info->addResponse<oatpp::String>(Status::CODE_400, "application/json");
137  info->addResponse<oatpp::String>(Status::CODE_404, "application/json");
138  }
139  ENDPOINT("PUT", "/api/configure/users/{username}/preset", setUserPreset,
140  PATH(String, username), REQUEST(std::shared_ptr<IncomingRequest>, request))
141  {
142  return handleSetUserPreset(request, username);
143  }
144 
145  ENDPOINT_INFO(setUserPassword)
146  {
147  info->summary = "Set or clear a user's password";
148  info->description =
149  "Sets the password for the given user. "
150  "Body: { \"password\": \"newPassword\" } "
151  "Send an empty string to remove the password requirement (open account). "
152  "Requires the 'users.write' permission.";
153  info->addTag("Configure");
154  info->pathParams["username"].description = "Username of the user to update";
155  info->addConsumes<oatpp::String>("application/json");
156  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
157  info->addResponse<oatpp::String>(Status::CODE_400, "application/json");
158  info->addResponse<oatpp::String>(Status::CODE_404, "application/json");
159  info->addResponse<oatpp::String>(Status::CODE_500, "application/json");
160  }
161  ENDPOINT("PUT", "/api/configure/users/{username}/password", setUserPassword,
162  PATH(String, username), REQUEST(std::shared_ptr<IncomingRequest>, request))
163  {
164  return handleSetUserPassword(request, username);
165  }
166 
167  ENDPOINT_INFO(getPresets)
168  {
169  info->summary = "List permission presets";
170  info->description =
171  "Returns all named permission presets defined in the users.json file. "
172  "Each preset is a named array of permission strings that can be assigned "
173  "to a user via the 'preset' field in POST /api/configure/users. "
174  "Requires the 'users.read' permission.";
175  info->addTag("Configure");
176  info->addResponse<oatpp::String>(Status::CODE_200, "application/json");
177  info->addResponse<oatpp::String>(Status::CODE_401, "application/json");
178  info->addResponse<oatpp::String>(Status::CODE_403, "application/json");
179  }
180  ENDPOINT("GET", "/api/configure/presets", getPresets,
181  REQUEST(std::shared_ptr<IncomingRequest>, request))
182  {
183  return handleGetPresets(request);
184  }
185 
186 private:
187  std::shared_ptr<OutgoingResponse> handleGetUsers(
188  const std::shared_ptr<IncomingRequest>& req);
189 
190  std::shared_ptr<OutgoingResponse> handleAddUser(
191  const std::shared_ptr<IncomingRequest>& req);
192 
193  std::shared_ptr<OutgoingResponse> handleDeleteUser(
194  const std::shared_ptr<IncomingRequest>& req, const String& username);
195 
196  std::shared_ptr<OutgoingResponse> handleSetUserPermissions(
197  const std::shared_ptr<IncomingRequest>& req, const String& username);
198 
199  std::shared_ptr<OutgoingResponse> handleSetUserPreset(
200  const std::shared_ptr<IncomingRequest>& req, const String& username);
201 
202  std::shared_ptr<OutgoingResponse> handleSetUserPassword(
203  const std::shared_ptr<IncomingRequest>& req, const String& username);
204 
205  std::shared_ptr<OutgoingResponse> handleGetPresets(
206  const std::shared_ptr<IncomingRequest>& req);
207 };
208 
209 #include OATPP_CODEGEN_END(ApiController)
ENDPOINT("PUT","/api/configure/users/{username}/permissions", setUserPermissions, PATH(String, username), REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:117
ENDPOINT_INFO(setUserPermissions)
Definition: usersController.h:102
std::shared_ptr< OutgoingResponse > handleAddUser(const std::shared_ptr< IncomingRequest > &req)
std::shared_ptr< OutgoingResponse > handleSetUserPassword(const std::shared_ptr< IncomingRequest > &req, const String &username)
ENDPOINT("PUT","/api/configure/users/{username}/password", setUserPassword, PATH(String, username), REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:161
ENDPOINT("PUT","/api/configure/users/{username}/preset", setUserPreset, PATH(String, username), REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:139
ENDPOINT_INFO(addUser)
Definition: usersController.h:59
ENDPOINT_INFO(setUserPassword)
Definition: usersController.h:145
ENDPOINT("DELETE","/api/configure/users/{username}", deleteUser, PATH(String, username), REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:96
std::shared_ptr< OutgoingResponse > handleGetPresets(const std::shared_ptr< IncomingRequest > &req)
ENDPOINT_INFO(deleteUser)
Definition: usersController.h:82
std::shared_ptr< OutgoingResponse > handleSetUserPreset(const std::shared_ptr< IncomingRequest > &req, const String &username)
DtUsersController — REST endpoints for managing the local user database at runtime.
Definition: usersController.h:32
ENDPOINT_INFO(getUsers)
Definition: usersController.h:40
std::shared_ptr< OutgoingResponse > handleSetUserPermissions(const std::shared_ptr< IncomingRequest > &req, const String &username)
ENDPOINT("GET","/api/configure/users", getUsers, REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:53
ENDPOINT("GET","/api/configure/presets", getPresets, REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:180
ENDPOINT_INFO(setUserPreset)
Definition: usersController.h:123
ENDPOINT_INFO(getPresets)
Definition: usersController.h:167
DtUsersController(const std::shared_ptr< ObjectMapper > &objectMapper)
Definition: usersController.h:35
ENDPOINT("POST","/api/configure/users", addUser, REQUEST(std::shared_ptr< IncomingRequest >, request))
Definition: usersController.h:76
std::shared_ptr< OutgoingResponse > handleDeleteUser(const std::shared_ptr< IncomingRequest > &req, const String &username)
std::shared_ptr< OutgoingResponse > handleGetUsers(const std::shared_ptr< IncomingRequest > &req)

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)