Changeset 435 for binary-improvements2/WebServer/src/WebAPI/APIs
- Timestamp:
- May 18, 2023, 12:20:16 PM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/WebAPI/APIs/Permissions/WebModules.cs
r434 r435 1 using System; 1 2 using System.Collections.Generic; 2 3 using System.Net; … … 67 68 _writer.WriteInt32 (_module.LevelGlobal); 68 69 _writer.WriteRaw (jsonKeyPermissionLevelPerMethod); 69 70 70 71 _writer.WriteBeginObject (); 71 72 … … 74 75 for (int iMethod = 0; iMethod < _module.LevelPerMethod.Length; iMethod++) { 75 76 int methodLevel = _module.LevelPerMethod [iMethod]; 76 77 77 78 if (methodLevel == AdminWebModules.MethodLevelNotSupported) { 78 79 continue; … … 84 85 85 86 first = false; 86 87 87 88 _writer.WriteRaw (jsonMethodNameKeys [iMethod]); 88 89 if (methodLevel == AdminWebModules.MethodLevelInheritGlobal) { 89 _writer.WriteString ( "inherit");90 _writer.WriteString (AdminWebModules.MethodLevelInheritKeyword); 90 91 } else { 91 92 _writer.WriteInt32 (methodLevel); … … 95 96 96 97 _writer.WriteEndObject (); 97 98 98 99 _writer.WriteRaw (jsonKeyIsDefault); 99 100 _writer.WriteBoolean (_module.IsDefault); 100 101 101 102 _writer.WriteEndObject (); 102 103 } … … 105 106 string id = _context.RequestPath; 106 107 107 // TODO108 109 108 if (string.IsNullOrEmpty (id)) { 110 109 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_MODULE"); … … 112 111 } 113 112 114 if (! JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelGlobal, out int permissionLevel)) {115 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, " NO_OR_INVALID_PERMISSION_LEVEL");113 if (!AdminWebModules.Instance.IsKnownModule (id)) { 114 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_MODULE"); 116 115 return; 117 116 } 118 117 119 // ModulesInstance.AddModule (id, permissionLevel); 118 AdminWebModules.WebModule module = AdminWebModules.Instance.GetModule (id); 119 120 if (_jsonInput.ContainsKey (propertyPermissionLevelGlobal)) { 121 if (!JsonCommons.TryGetJsonField (_jsonInput, propertyPermissionLevelGlobal, out int permissionLevelGlobal)) { 122 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_LEVEL_GLOBAL"); 123 return; 124 } 125 126 module.LevelGlobal = permissionLevelGlobal; 127 } 128 129 if (_jsonInput.TryGetValue (propertyPermissionLevelPerMethod, out object perLevelField)) { 130 if (perLevelField is not IDictionary<string, object> perLevelObj) { 131 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_LEVEL_PER_METHOD_PROPERTY"); 132 return; 133 } 134 135 foreach ((string property, object valueObj) in perLevelObj) { 136 if (!EnumUtils.TryParse (property, out ERequestMethod method, true)) { 137 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_METHOD_NAME"); 138 return; 139 } 140 141 if (module.LevelPerMethod == null || module.LevelPerMethod [(int)method] == AdminWebModules.MethodLevelNotSupported) { 142 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "UNSUPPORTED_METHOD"); 143 return; 144 } 145 146 int permissionLevel; 147 148 if (valueObj is string valueString) { 149 if (!valueString.EqualsCaseInsensitive (AdminWebModules.MethodLevelInheritKeyword)) { 150 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_STRING"); 151 return; 152 } 153 154 permissionLevel = AdminWebModules.MethodLevelInheritGlobal; 155 } else if (valueObj is double valueDbl) { 156 try { 157 permissionLevel = (int)valueDbl; 158 } catch (Exception) { 159 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_VALUE"); 160 return; 161 } 162 } else { 163 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "INVALID_PERMISSION_VALUE_TYPE"); 164 return; 165 } 166 167 module.LevelPerMethod [(int)method] = permissionLevel; 168 } 169 } 170 171 module.IsDefault = false; 172 ModulesInstance.AddModule (module); 120 173 121 174 SendEmptyResponse (_context, HttpStatusCode.Created);
Note:
See TracChangeset
for help on using the changeset viewer.