Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BrokerNotificationConfiguration.cs
2using System.Threading.Tasks;
3using Waher.Content;
10
12{
17 {
18 private static BrokerNotificationConfiguration instance = null;
19
20 private HttpResource setRegistration = null;
21
22 private bool accountCreated = true;
23 private bool accountDeleted = true;
24 private bool legalIdReceived = true;
25 private bool otherLegalIds = true;
26 private bool peerReviewApproved = true;
27 private bool legalIdAutoApproved = true;
28 private bool legalIdAutoRejected = true;
29 private bool contractProposalReceived = true;
30 private bool accountRecoveryRequest = true;
31 private bool apiKeyCreated = true;
32 private bool feedbackReceived = true;
33 private bool accountRequested = true;
34 private bool apiKeyRequested = true;
35
39 public static BrokerNotificationConfiguration Instance => instance;
40
44 public override string Resource => "/Settings/BrokerNotifications.md";
45
49 public override int Priority => 610;
50
54 [DefaultValue(true)]
55 public bool AccountCreated
56 {
57 get => this.accountCreated;
58 set => this.accountCreated = value;
59 }
60
64 [DefaultValue(true)]
65 public bool AccountDeleted
66 {
67 get => this.accountDeleted;
68 set => this.accountDeleted = value;
69 }
70
74 [DefaultValue(true)]
75 public bool LegalIdReceived
76 {
77 get => this.legalIdReceived;
78 set => this.legalIdReceived = value;
79 }
80
85 [DefaultValue(true)]
86 public bool OtherLegalIds
87 {
88 get => this.otherLegalIds;
89 set => this.otherLegalIds = value;
90 }
91
96 [DefaultValue(true)]
98 {
99 get => this.peerReviewApproved;
100 set => this.peerReviewApproved = value;
101 }
102
107 [DefaultValue(true)]
109 {
110 get => this.legalIdAutoApproved;
111 set => this.legalIdAutoApproved = value;
112 }
113
118 [DefaultValue(true)]
120 {
121 get => this.legalIdAutoRejected;
122 set => this.legalIdAutoRejected = value;
123 }
124
128 [DefaultValue(true)]
130 {
131 get => this.contractProposalReceived;
132 set => this.contractProposalReceived = value;
133 }
134
139 [DefaultValue(true)]
141 {
142 get => this.accountRecoveryRequest;
143 set => this.accountRecoveryRequest = value;
144 }
145
149 [DefaultValue(true)]
150 public bool ApiKeyCreated
151 {
152 get => this.apiKeyCreated;
153 set => this.apiKeyCreated = value;
154 }
155
159 [DefaultValue(true)]
161 {
162 get => this.feedbackReceived;
163 set => this.feedbackReceived = value;
164 }
165
169 [DefaultValue(true)]
171 {
172 get => this.accountRequested;
173 set => this.accountRequested = value;
174 }
175
179 [DefaultValue(true)]
180 public bool ApiKeyRequested
181 {
182 get => this.apiKeyRequested;
183 set => this.apiKeyRequested = value;
184 }
185
191 public override Task<string> Title(Language Language)
192 {
193 return Language.GetStringAsync(typeof(XmppServerModule), 44, "Broker Notifications");
194 }
195
199 public override Task ConfigureSystem()
200 {
201 return Task.CompletedTask;
202 }
203
208 public override void SetStaticInstance(ISystemConfiguration Configuration)
209 {
210 instance = Configuration as BrokerNotificationConfiguration;
211 }
212
217 public override Task InitSetup(HttpServer WebServer)
218 {
219 this.setRegistration = WebServer.Register("/Settings/SetBrokerNotifications",
220 null, this.SetRegistration, true, false, true);
221
222 return base.InitSetup(WebServer);
223 }
224
228 protected override string ConfigPrivilege => "Admin.Broker.Notifications";
229
230 private async Task SetRegistration(HttpRequest Request, HttpResponse Response)
231 {
232 Gateway.AssertUserAuthenticated(Request, this.ConfigPrivilege);
233
234 if (!Request.HasData)
235 {
236 await Response.SendResponse(new BadRequestException());
237 return;
238 }
239
240 ContentResponse Content = await Request.DecodeDataAsync();
241 if (Content.HasError ||
242 !(Content.Decoded is Dictionary<string, object> Parameters))
243 {
244 await Response.SendResponse(new BadRequestException());
245 return;
246 }
247
248 if (!Parameters.TryGetValue("accountCreated", out object Obj) || !(Obj is bool AccountCreated) ||
249 !Parameters.TryGetValue("accountDeleted", out Obj) || !(Obj is bool AccountDeleted) ||
250 !Parameters.TryGetValue("legalIdReceived", out Obj) || !(Obj is bool LegalIdReceived) ||
251 !Parameters.TryGetValue("otherLegalIds", out Obj) || !(Obj is bool OtherLegalIds) ||
252 !Parameters.TryGetValue("peerReviewApproved", out Obj) || !(Obj is bool PeerReviewApproved) ||
253 !Parameters.TryGetValue("legalIdAutoApproved", out Obj) || !(Obj is bool LegalIdAutoApproved) ||
254 !Parameters.TryGetValue("legalIdAutoRejected", out Obj) || !(Obj is bool LegalIdAutoRejected) ||
255 !Parameters.TryGetValue("contractProposalReceived", out Obj) || !(Obj is bool ContractProposalReceived) ||
256 !Parameters.TryGetValue("accountRecoveryRequest", out Obj) || !(Obj is bool AccountRecoveryRequest) ||
257 !Parameters.TryGetValue("apiKeyCreated", out Obj) || !(Obj is bool ApiKeyCreated) ||
258 !Parameters.TryGetValue("feedbackReceived", out Obj) || !(Obj is bool FeedbackReceived) ||
259 !Parameters.TryGetValue("accountRequested", out Obj) || !(Obj is bool AccountRequested) ||
260 !Parameters.TryGetValue("apiKeyRequested", out Obj) || !(Obj is bool ApiKeyRequested))
261 {
262 await Response.SendResponse(new BadRequestException());
263 return;
264 }
265
266 this.accountCreated = AccountCreated;
267 this.accountDeleted = AccountDeleted;
268 this.legalIdReceived = LegalIdReceived;
269 this.otherLegalIds = OtherLegalIds;
270 this.peerReviewApproved = PeerReviewApproved;
271 this.legalIdAutoApproved = LegalIdAutoApproved;
272 this.legalIdAutoRejected = LegalIdAutoRejected;
273 this.contractProposalReceived = ContractProposalReceived;
274 this.accountRecoveryRequest = AccountRecoveryRequest;
275 this.apiKeyCreated = ApiKeyCreated;
276 this.feedbackReceived = FeedbackReceived;
277 this.accountRequested = AccountRequested;
278 this.apiKeyRequested = ApiKeyRequested;
279
280 Response.StatusCode = 200;
281 Response.StatusMessage = "OK";
282
283 await Database.Update(this);
284 }
285
290 public override Task UnregisterSetup(HttpServer WebServer)
291 {
292 WebServer.Unregister(this.setRegistration);
293
294 return base.UnregisterSetup(WebServer);
295 }
296
301 public override Task<bool> SimplifiedConfiguration()
302 {
303 this.accountCreated = true;
304 this.accountDeleted = true;
305 this.legalIdReceived = true;
306 this.otherLegalIds = true;
307 this.peerReviewApproved = true;
308 this.legalIdAutoApproved = true;
309 this.legalIdAutoRejected = true;
310 this.contractProposalReceived = true;
311 this.accountRecoveryRequest = true;
312 this.apiKeyCreated = true;
313 this.feedbackReceived = true;
314 this.accountRequested = true;
315 this.apiKeyRequested = true;
316
317 return Task.FromResult(true);
318 }
319
324
329
334
340
346
352
358
363
369
374
379
384
389
394 public override Task<bool> EnvironmentConfiguration()
395 {
396 if (!this.TryGetEnvironmentVariable(BROKER_NOT_ACCOUNT_CREATED, out this.accountCreated, true) ||
397 !this.TryGetEnvironmentVariable(BROKER_NOT_ACCOUNT_DELETED, out this.accountDeleted, true) ||
398 !this.TryGetEnvironmentVariable(BROKER_NOT_LEGAL_ID_RECEIVED, out this.legalIdReceived, true) ||
399 !this.TryGetEnvironmentVariable(BROKER_NOT_OTHER_LEGAL_IDS, out this.otherLegalIds, true) ||
400 !this.TryGetEnvironmentVariable(BROKER_NOT_PEER_REVIEW_APPROVED, out this.peerReviewApproved, true) ||
401 !this.TryGetEnvironmentVariable(BROKER_NOT_LEGAL_ID_AUTO_APPROVED, out this.legalIdAutoApproved, true) ||
402 !this.TryGetEnvironmentVariable(BROKER_NOT_LEGAL_ID_AUTO_REJECTED, out this.legalIdAutoRejected, true) ||
403 !this.TryGetEnvironmentVariable(BROKER_NOT_CONTRACT_PROPOSAL_RECEIVED, out this.contractProposalReceived, true) ||
404 !this.TryGetEnvironmentVariable(BROKER_NOT_ACCOUNT_RECOVERY_REQUEST, out this.accountRecoveryRequest, true) ||
405 !this.TryGetEnvironmentVariable(BROKER_NOT_API_KEY_CREATED, out this.apiKeyCreated, true) ||
406 !this.TryGetEnvironmentVariable(BROKER_NOT_FEEDBACK_RECEIVED, out this.feedbackReceived, true) ||
407 !this.TryGetEnvironmentVariable(BROKER_NOT_ACCOUNT_REQUESTED, out this.accountRequested, true) ||
408 !this.TryGetEnvironmentVariable(BROKER_NOT_API_KEY_REQUESTED, out this.apiKeyRequested, true))
409 {
410 return Task.FromResult(false);
411 }
412
413 return Task.FromResult(true);
414 }
415
416 }
417}
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static IUser AssertUserAuthenticated(HttpRequest Request, string Privilege)
Makes sure a request is being made from a session with a successful user login.
Definition: Gateway.cs:3868
Abstract base class for system configurations.
bool TryGetEnvironmentVariable(string VariableName, bool Required, out string Value)
Tries to get a string-valued environment variable.
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
Represents an HTTP request.
Definition: HttpRequest.cs:22
bool HasData
If the request has data.
Definition: HttpRequest.cs:113
async Task< ContentResponse > DecodeDataAsync()
Decodes data sent in request.
Definition: HttpRequest.cs:139
Base class for all HTTP resources.
Definition: HttpResource.cs:23
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Implements an HTTP server.
Definition: HttpServer.cs:41
HttpResource Register(HttpResource Resource)
Registers a resource with the server.
Definition: HttpServer.cs:1568
bool Unregister(HttpResource Resource)
Unregisters a resource from the server.
Definition: HttpServer.cs:1743
Static interface for database persistence. In order to work, a database provider has to be assigned t...
Definition: Database.cs:21
static async Task Update(object Object)
Updates an object in the database.
Definition: Database.cs:1211
Contains information about a language.
Definition: Language.cs:17
Task< string > GetStringAsync(Type Type, int Id, string Default)
Gets the string value of a string ID. If no such string exists, a string is created with the default ...
Definition: Language.cs:209
Provides the user with options to control notifications from the Broker.
string BROKER_NOT_API_KEY_CREATED
true or 1 if a notification should be sent when an API key has been created.
string BROKER_NOT_PEER_REVIEW_APPROVED
true or 1 if a notification should be sent when a peer review of a Legal ID has been approved.
bool AccountCreated
If a notification should be sent when a new account is created.
string BROKER_NOT_API_KEY_REQUESTED
true or 1 if a notification should be sent when an API key has been requested.
string BROKER_NOT_ACCOUNT_REQUESTED
true or 1 if a notification should be sent when an account has been requested.
string BROKER_NOT_FEEDBACK_RECEIVED
true or 1 if a notification should be sent when feedback has been received.
override Task ConfigureSystem()
Is called during startup to configure the system.
static BrokerNotificationConfiguration Instance
Current instance of configuration.
override Task< bool > SimplifiedConfiguration()
Simplified configuration by configuring simple default values.
bool PeerReviewApproved
If a notification should be sent when a peer review of a Legal ID has been approved.
override Task< string > Title(Language Language)
Gets a title for the system configuration.
override Task< bool > EnvironmentConfiguration()
Environment configuration by configuring values available in environment variables.
bool OtherLegalIds
If a notification should be sent for every existing valid Legal ID that exists when a new Legal ID ap...
bool AccountRequested
If a notification should be sent when an account has been requested.
override Task UnregisterSetup(HttpServer WebServer)
Unregisters the setup object.
string BROKER_NOT_CONTRACT_PROPOSAL_RECEIVED
true or 1 if a notification should be sent when a contract proposal has been received.
string BROKER_NOT_ACCOUNT_RECOVERY_REQUEST
true or 1 if a notification should be sent when an account recovery request has been received.
string BROKER_NOT_ACCOUNT_CREATED
true or 1 if a notification should be sent when a new account is created.
bool LegalIdAutoRejected
If a notification should be sent when a Legal ID application has been automatically rejected.
bool LegalIdAutoApproved
If a notification should be sent when a Legal ID application has been automatically approved.
bool LegalIdReceived
If a notification should be sent when a new a Legal ID application is received.
bool ApiKeyRequested
If a notification should be sent when an API key has been requested.
bool ContractProposalReceived
If a notification should be sent when a contract proposal has been received.
string BROKER_NOT_OTHER_LEGAL_IDS
true or 1 if a notification should be sent for every existing valid Legal ID that exists when a new L...
string BROKER_NOT_LEGAL_ID_AUTO_APPROVED
true or 1 if a notification should be sent when a Legal ID application has been automatically approve...
bool AccountRecoveryRequest
If a notification should be sent when an account recovery request has been received.
override Task InitSetup(HttpServer WebServer)
Initializes the setup object.
string BROKER_NOT_ACCOUNT_DELETED
true or 1 if a notification should be sent when a new account is deleted.
override int Priority
Priority of the setting. Configurations are sorted in ascending order.
string BROKER_NOT_LEGAL_ID_RECEIVED
true or 1 if a notification should be sent when a new a Legal ID application is received.
bool ApiKeyCreated
If a notification should be sent when an API key has been created.
bool AccountDeleted
If a notification should be sent when a new account is deleted.
override void SetStaticInstance(ISystemConfiguration Configuration)
Sets the static instance of the configuration.
override string ConfigPrivilege
Minimum required privilege for a user to be allowed to change the configuration defined by the class.
bool FeedbackReceived
If a notification should be sent when feedback has been received.
string BROKER_NOT_LEGAL_ID_AUTO_REJECTED
true or 1 if a notification should be sent when a Legal ID application has been automatically rejecte...
Service Module hosting the XMPP broker and its components.
Interface for system configurations. The gateway will scan all module for system configuration classe...