Skip to content

Commit f005d67

Browse files
Andrei SalanovichAndrei Salanovich
authored andcommitted
Merge remote-tracking branch 'origin/main' into feature/352_ui-change-script-ps-version
2 parents dba890f + 9a26898 commit f005d67

File tree

52 files changed

+1665
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1665
-171
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
using Dorc.ApiModel;
2+
using Dorc.PersistentData.Sources.Interfaces;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Dorc.Api.Controllers
7+
{
8+
[Route("[controller]")]
9+
[ApiController]
10+
public class AnalyticsController : ControllerBase
11+
{
12+
private readonly IAnalyticsPersistentSource _analyticsPersistentSource;
13+
private readonly ILogger<AnalyticsController> _logger;
14+
15+
public AnalyticsController(
16+
IAnalyticsPersistentSource analyticsPersistentSource,
17+
ILogger<AnalyticsController> logger)
18+
{
19+
_analyticsPersistentSource = analyticsPersistentSource;
20+
_logger = logger;
21+
}
22+
23+
[HttpGet("EnvironmentUsage")]
24+
public ActionResult<IEnumerable<AnalyticsEnvironmentUsageApiModel>> GetEnvironmentUsage()
25+
{
26+
try
27+
{
28+
var data = _analyticsPersistentSource.GetEnvironmentUsage();
29+
return Ok(data);
30+
}
31+
catch (Exception ex)
32+
{
33+
_logger.LogError(ex, "Error retrieving environment usage analytics");
34+
return StatusCode(500, "An error occurred while retrieving environment usage data");
35+
}
36+
}
37+
38+
[HttpGet("UserActivity")]
39+
public ActionResult<IEnumerable<AnalyticsUserActivityApiModel>> GetUserActivity()
40+
{
41+
try
42+
{
43+
var data = _analyticsPersistentSource.GetUserActivity();
44+
return Ok(data);
45+
}
46+
catch (Exception ex)
47+
{
48+
_logger.LogError(ex, "Error retrieving user activity analytics");
49+
return StatusCode(500, "An error occurred while retrieving user activity data");
50+
}
51+
}
52+
53+
[HttpGet("TimePattern")]
54+
public ActionResult<IEnumerable<AnalyticsTimePatternApiModel>> GetTimePattern()
55+
{
56+
try
57+
{
58+
var data = _analyticsPersistentSource.GetTimePatterns();
59+
return Ok(data);
60+
}
61+
catch (Exception ex)
62+
{
63+
_logger.LogError(ex, "Error retrieving time pattern analytics");
64+
return StatusCode(500, "An error occurred while retrieving time pattern data");
65+
}
66+
}
67+
68+
[HttpGet("ComponentUsage")]
69+
public ActionResult<IEnumerable<AnalyticsComponentUsageApiModel>> GetComponentUsage()
70+
{
71+
try
72+
{
73+
var data = _analyticsPersistentSource.GetComponentUsage();
74+
return Ok(data);
75+
}
76+
catch (Exception ex)
77+
{
78+
_logger.LogError(ex, "Error retrieving component usage analytics");
79+
return StatusCode(500, "An error occurred while retrieving component usage data");
80+
}
81+
}
82+
83+
[HttpGet("Duration")]
84+
public ActionResult<AnalyticsDurationApiModel> GetDuration()
85+
{
86+
try
87+
{
88+
var data = _analyticsPersistentSource.GetDeploymentDuration();
89+
return Ok(data);
90+
}
91+
catch (Exception ex)
92+
{
93+
_logger.LogError(ex, "Error retrieving deployment duration analytics");
94+
return StatusCode(500, "An error occurred while retrieving deployment duration data");
95+
}
96+
}
97+
}
98+
}

src/Dorc.Api/Controllers/RefDataConfigController.cs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ public IActionResult Get()
4444
[SwaggerResponse(StatusCodes.Status200OK, Type = typeof(ConfigValueApiModel))]
4545
public IActionResult Post([FromBody] ConfigValueApiModel model)
4646
{
47-
return !_rolePrivilegesChecker.IsAdmin(User)
48-
? Forbid()
49-
: Ok(_configValuesPersistentSource.Add(model));
47+
if (!_rolePrivilegesChecker.IsAdmin(User))
48+
return Forbid();
49+
try
50+
{
51+
return Ok(_configValuesPersistentSource.Add(model));
52+
}
53+
catch (Exception ex)
54+
{
55+
return BadRequest(ex.Message);
56+
}
5057
}
5158

5259
/// <summary>
@@ -59,15 +66,16 @@ public IActionResult Post([FromBody] ConfigValueApiModel model)
5966
[SwaggerResponse(StatusCodes.Status200OK, Type = typeof(ConfigValueApiModel))]
6067
public IActionResult Put(int id, [FromBody] ConfigValueApiModel model)
6168
{
62-
return !_rolePrivilegesChecker.IsAdmin(User)
63-
? Forbid()
64-
: Ok(_configValuesPersistentSource.UpdateConfigValue(new ConfigValue
65-
{
66-
Secure = model.Secure,
67-
Id = model.Id,
68-
Key = model.Key,
69-
Value = model.Value
70-
}));
69+
if (!_rolePrivilegesChecker.IsAdmin(User))
70+
return Forbid();
71+
try
72+
{
73+
return Ok(_configValuesPersistentSource.UpdateConfigValue(model));
74+
}
75+
catch (Exception ex)
76+
{
77+
return BadRequest(ex.Message);
78+
}
7179
}
7280

7381
/// <summary>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Dorc.ApiModel
2+
{
3+
public class AnalyticsComponentUsageApiModel
4+
{
5+
public string ComponentName { get; set; }
6+
public int CountOfDeployments { get; set; }
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Dorc.ApiModel
2+
{
3+
public class AnalyticsDurationApiModel
4+
{
5+
public double AverageDurationMinutes { get; set; }
6+
public double MaxDurationMinutes { get; set; }
7+
public double MinDurationMinutes { get; set; }
8+
public int TotalDeployments { get; set; }
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Dorc.ApiModel
2+
{
3+
public class AnalyticsEnvironmentUsageApiModel
4+
{
5+
public string EnvironmentName { get; set; }
6+
public int CountOfDeployments { get; set; }
7+
public int Failed { get; set; }
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Dorc.ApiModel
2+
{
3+
public class AnalyticsTimePatternApiModel
4+
{
5+
public int HourOfDay { get; set; }
6+
public int DayOfWeek { get; set; }
7+
public string DayOfWeekName { get; set; }
8+
public int CountOfDeployments { get; set; }
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Dorc.ApiModel
2+
{
3+
public class AnalyticsUserActivityApiModel
4+
{
5+
public string UserName { get; set; }
6+
public int CountOfDeployments { get; set; }
7+
public int Failed { get; set; }
8+
}
9+
}

src/Dorc.ApiModel/ConfigValueApiModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class ConfigValueApiModel
1010
public string Key { get; set; }
1111
public string Value { get; set; }
1212
public bool Secure { get; set; }
13+
public Nullable<bool> IsForProd { get; set; }
1314
}
1415
}
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +0,0 @@
1-
-- Migration script to preserve environment history audit records when environments are deleted
2-
-- This modifies the foreign key constraint to allow EnvId to be set to NULL when environment is deleted
3-
4-
-- First, make the EnvId column nullable to allow orphaned audit records
5-
ALTER TABLE [deploy].[EnvironmentHistory]
6-
ALTER COLUMN [EnvId] INT NULL;
7-
8-
-- Drop the existing foreign key constraint
9-
ALTER TABLE [deploy].[EnvironmentHistory]
10-
DROP CONSTRAINT [EnvironmentHistory_Environment_Env_ID_fk];
11-
12-
-- Recreate the foreign key constraint with SET NULL on delete
13-
-- This will preserve audit records by setting EnvId to NULL when environment is deleted
14-
ALTER TABLE [deploy].[EnvironmentHistory]
15-
ADD CONSTRAINT [EnvironmentHistory_Environment_Env_ID_fk]
16-
FOREIGN KEY ([EnvId])
17-
REFERENCES [deploy].[Environment] ([Id])
18-
ON DELETE SET NULL;

src/Dorc.Database/Dorc.Database.sqlproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,17 @@
358358
<Build Include="deploy\Stored Procedures\ArchiveDeploymentRequests.sql" />
359359
<Build Include="Schema Objects\Schemas\archive\Tables\EnvironmentComponentStatus.table.sql" />
360360
<None Include="Scripts\Post-Deployment\Environment_AccessControl_Populate.sql" />
361+
<Build Include="deploy\Stored Procedures\get_property_values_for_user.sql" />
362+
<Build Include="deploy\Stored Procedures\sp_PopulateAnalyticsComponentUsage.sql" />
363+
<Build Include="deploy\Stored Procedures\sp_PopulateAnalyticsDuration.sql" />
364+
<Build Include="deploy\Stored Procedures\sp_PopulateAnalyticsEnvironmentUsage.sql" />
365+
<Build Include="deploy\Stored Procedures\sp_PopulateAnalyticsTimePattern.sql" />
366+
<Build Include="deploy\Stored Procedures\sp_PopulateAnalyticsUserActivity.sql" />
367+
<Build Include="deploy\Tables\AnalyticsComponentUsage.sql" />
368+
<Build Include="deploy\Tables\AnalyticsDuration.sql" />
369+
<Build Include="deploy\Tables\AnalyticsEnvironmentUsage.sql" />
370+
<Build Include="deploy\Tables\AnalyticsTimePattern.sql" />
371+
<Build Include="deploy\Tables\AnalyticsUserActivity.sql" />
361372
</ItemGroup>
362373
<ItemGroup>
363374
<None Include="Schema Comparisons\LocalToProject.scmp">
@@ -366,6 +377,7 @@
366377
<Build Include="Schema Objects\Database Level Objects\Security\Schemas\archive.schema.sql" />
367378
<Build Include="Schema Objects\Schemas\deploy\Tables\Indexes\IX_PropertyValueFilter_PropertyValueId.index.sql" />
368379
<Build Include="Schema Objects\Schemas\deploy\Tables\Indexes\IX_PropertyValue_PropertyId.index.sql" />
380+
<None Include="Scripts\Post-Deployment\Props-to-Configuration.sql" />
369381
</ItemGroup>
370382
<ItemGroup>
371383
<PreDeploy Include="Scripts\Pre-Deployment\Script.PreDeployment.sql" />

0 commit comments

Comments
 (0)