- Timestamp:
- Feb 16, 2023, 3:50:53 PM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/UrlHandlers/ApiHandler.cs
r402 r404 3 3 using System.Net; 4 4 using System.Reflection; 5 using Webserver.Permissions; 5 6 using Webserver.WebAPI; 6 7 … … 10 11 11 12 public ApiHandler () : base (null) { 12 13 13 } 14 15 private static readonly Type[] apiWithParentCtorTypes = { typeof (Web) }; 16 private static readonly object[] apiWithParentCtorArgs = new object[1]; 17 private static readonly Type[] apiEmptyCtorTypes = { }; 18 private static readonly object[] apiEmptyCtorArgs = { }; 14 19 15 20 public override void SetBasePathAndParent (Web _parent, string _relativePath) { 16 21 base.SetBasePathAndParent (_parent, _relativePath); 17 22 18 Type[] apiWithParentCtorTypes = { typeof (Web) }; 19 object[] apiWithParentCtorArgs = { _parent }; 23 apiWithParentCtorArgs[0] = _parent; 20 24 21 Type[] apiEmptyCtorTypes = { }; 22 object[] apiEmptyCtorArgs = { }; 23 24 25 ReflectionHelpers.FindTypesImplementingBase (typeof (AbsWebAPI), _type => { 26 ConstructorInfo ctor = _type.GetConstructor (apiWithParentCtorTypes); 27 if (ctor != null) { 28 AbsWebAPI apiInstance = (AbsWebAPI) ctor.Invoke (apiWithParentCtorArgs); 29 addApi (apiInstance); 30 return; 31 } 32 33 ctor = _type.GetConstructor (apiEmptyCtorTypes); 34 if (ctor != null) { 35 AbsWebAPI apiInstance = (AbsWebAPI) ctor.Invoke (apiEmptyCtorArgs); 36 addApi (apiInstance); 37 } 38 }); 25 ReflectionHelpers.FindTypesImplementingBase (typeof (AbsWebAPI), apiFoundCallback); 39 26 40 27 // Permissions that don't map to a real API … … 43 30 } 44 31 32 private void apiFoundCallback (Type _type) { 33 ConstructorInfo ctor = _type.GetConstructor (apiWithParentCtorTypes); 34 if (ctor != null) { 35 AbsWebAPI apiInstance = (AbsWebAPI)ctor.Invoke (apiWithParentCtorArgs); 36 addApi (apiInstance); 37 return; 38 } 39 40 ctor = _type.GetConstructor (apiEmptyCtorTypes); 41 if (ctor != null) { 42 AbsWebAPI apiInstance = (AbsWebAPI)ctor.Invoke (apiEmptyCtorArgs); 43 addApi (apiInstance); 44 } 45 } 46 45 47 private void addApi (AbsWebAPI _api) { 46 48 apis.Add (_api.Name, _api); 47 WebPermissions.Instance.AddKnownModule ($"webapi.{_api.Name}", _api.DefaultPermissionLevel ());49 AdminWebModules.Instance.AddKnownModule ($"webapi.{_api.Name}", _api.DefaultPermissionLevel ()); 48 50 } 49 51 … … 92 94 93 95 private bool IsAuthorizedForApi (string _apiName, int _permissionLevel) { 94 return WebPermissions.Instance.ModuleAllowedWithLevel ($"webapi.{_apiName}", _permissionLevel);96 return AdminWebModules.Instance.ModuleAllowedWithLevel ($"webapi.{_apiName}", _permissionLevel); 95 97 } 96 98 }
Note:
See TracChangeset
for help on using the changeset viewer.