@@ -16,7 +16,7 @@ public class AdminController(ConfigurationOptions options, HangfireLauncherServi
16
16
/// Enqueues a job that updates xmldoc content from the latest release/pre-release tags.
17
17
/// </summary>
18
18
/// <returns>The unique identifier of the enqueued job.</returns>
19
- [ Authorize ( "github" , Roles = RDConstants . AdminRole ) ]
19
+ [ Authorize ( "github" , Roles = RDConstants . Roles . AdminRole ) ]
20
20
[ HttpPost ( "admin/update/xmldoc" ) ]
21
21
public IActionResult UpdateXmldocContent ( )
22
22
{
@@ -28,43 +28,96 @@ public IActionResult UpdateXmldocContent()
28
28
/// Enqueues a job that gets the latest release/pre-release tags and their respective assets, and updates the installer download stats.
29
29
/// </summary>
30
30
/// <returns>The unique identifier of the enqueued job.</returns>
31
- [ Authorize ( "github" , Roles = RDConstants . AdminRole ) ]
31
+ [ Authorize ( "github" , Roles = RDConstants . Roles . AdminRole ) ]
32
32
[ HttpPost ( "admin/update/tags" ) ]
33
33
public IActionResult UpdateTagMetadata ( )
34
34
{
35
35
var jobId = hangfire . UpdateTagMetadata ( ) ;
36
36
return Ok ( jobId ) ;
37
37
}
38
38
39
- [ Authorize ( "github" , Roles = RDConstants . AdminRole ) ]
39
+ [ Authorize ( "github" , Roles = RDConstants . Roles . AdminRole ) ]
40
40
[ HttpPost ( "admin/cache/clear" ) ]
41
41
public IActionResult ClearCache ( )
42
42
{
43
43
cache . Clear ( ) ;
44
44
return Ok ( ) ;
45
45
}
46
46
47
- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
47
+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } , { RDConstants . Roles . WriterRole } ") ]
48
48
[ HttpGet ( "admin/audits/pending" ) ]
49
49
public async Task < IActionResult > GetPendingAudits ( )
50
50
{
51
- var edits = await audits . GetPendingItems < FeatureEditEntity > ( ) ;
52
- var ops = await audits . GetPendingItems < FeatureOpEntity > ( ) ;
51
+ var edits = await audits . GetPendingItems < FeatureEditViewEntity > ( User . Identity ) ;
52
+ var ops = await audits . GetPendingItems < FeatureOpEntity > ( User . Identity ) ;
53
53
54
54
return Ok ( new { edits = edits . ToArray ( ) , other = ops . ToArray ( ) } ) ;
55
55
}
56
56
57
- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
58
- [ HttpGet ( "admin/audits/{featureId}" ) ]
57
+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ,{ RDConstants . Roles . WriterRole } ") ]
58
+ [ HttpGet ( "profile/activity" ) ]
59
+ public async Task < IActionResult > GetUserActivity ( )
60
+ {
61
+ if ( User . Identity is not IIdentity identity )
62
+ {
63
+ // this is arguably a bug in the authentication middleware, but we can handle it gracefully here
64
+ return Unauthorized ( "User identity is not available." ) ;
65
+ }
66
+
67
+ var activity = await audits . GetAllActivity ( identity ) ;
68
+ return Ok ( activity ) ;
69
+ }
70
+
71
+ private static readonly AuditActivityType [ ] EditActivityTypes = [
72
+ AuditActivityType . SubmitEdit ,
73
+ AuditActivityType . ApproveEdit ,
74
+ AuditActivityType . RejectEdit
75
+ ] ;
76
+
77
+ private static readonly AuditActivityType [ ] OpActivityTypes = [
78
+ AuditActivityType . SubmitCreate ,
79
+ AuditActivityType . ApproveCreate ,
80
+ AuditActivityType . RejectCreate ,
81
+ AuditActivityType . SubmitDelete ,
82
+ AuditActivityType . ApproveDelete ,
83
+ AuditActivityType . RejectDelete
84
+ ] ;
85
+
86
+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ") ]
87
+ [ HttpGet ( "admin/audits/{id}" ) ]
88
+ public async Task < IActionResult > GetAudit ( [ FromRoute ] int id , [ FromQuery ] string type )
89
+ {
90
+ if ( ! Enum . TryParse < AuditActivityType > ( type , ignoreCase : true , out var validType ) )
91
+ {
92
+ return BadRequest ( "Invalid activity type." ) ;
93
+ }
94
+
95
+ var edit = ( FeatureEditViewEntity ? ) null ;
96
+ var op = ( FeatureOpEntity ? ) null ;
97
+
98
+ if ( EditActivityTypes . Contains ( validType ) )
99
+ {
100
+ edit = await audits . GetItem < FeatureEditViewEntity > ( id ) ;
101
+ }
102
+ else if ( OpActivityTypes . Contains ( validType ) )
103
+ {
104
+ op = await audits . GetItem < FeatureOpEntity > ( id ) ;
105
+ }
106
+
107
+ return Ok ( new { edits = new [ ] { edit } , other = op is null ? [ ] : new [ ] { op } } ) ;
108
+ }
109
+
110
+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ") ]
111
+ [ HttpGet ( "admin/audits/feature/{featureId}" ) ]
59
112
public async Task < IActionResult > GetPendingAudits ( [ FromRoute ] int featureId )
60
113
{
61
- var edits = await audits . GetPendingItems < FeatureEditEntity > ( featureId ) ;
62
- var ops = await audits . GetPendingItems < FeatureOpEntity > ( featureId ) ;
114
+ var edits = await audits . GetPendingItems < FeatureEditEntity > ( User . Identity , featureId ) ;
115
+ var ops = await audits . GetPendingItems < FeatureOpEntity > ( User . Identity , featureId ) ;
63
116
64
117
return Ok ( new { edits = edits . ToArray ( ) , other = ops . ToArray ( ) } ) ;
65
118
}
66
119
67
- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
120
+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ") ]
68
121
[ HttpPost ( "admin/audits/approve/{id}" ) ]
69
122
public async Task < IActionResult > ApprovePendingAudit ( [ FromRoute ] int id )
70
123
{
@@ -74,13 +127,13 @@ public async Task<IActionResult> ApprovePendingAudit([FromRoute] int id)
74
127
return Unauthorized ( "User identity is not available." ) ;
75
128
}
76
129
77
- var edits = await audits . GetPendingItems < FeatureEditEntity > ( ) ;
130
+ var edits = await audits . GetPendingItems < FeatureEditEntity > ( User . Identity ) ;
78
131
AuditEntity ? audit ;
79
132
80
133
audit = edits . SingleOrDefault ( e => e . Id == id ) ;
81
134
if ( audit is null )
82
135
{
83
- var ops = await audits . GetPendingItems < FeatureOpEntity > ( ) ;
136
+ var ops = await audits . GetPendingItems < FeatureOpEntity > ( User . Identity ) ;
84
137
audit = ops . SingleOrDefault ( e => e . Id == id ) ;
85
138
}
86
139
@@ -100,7 +153,7 @@ public async Task<IActionResult> ApprovePendingAudit([FromRoute] int id)
100
153
return Ok ( "Operation was approved successfully." ) ;
101
154
}
102
155
103
- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
156
+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ") ]
104
157
[ HttpPost ( "admin/audits/reject/{id}" ) ]
105
158
public async Task < IActionResult > RejectPendingAudit ( [ FromRoute ] int id )
106
159
{
@@ -110,13 +163,13 @@ public async Task<IActionResult> RejectPendingAudit([FromRoute] int id)
110
163
return Unauthorized ( "User identity is not available." ) ;
111
164
}
112
165
113
- var edits = await audits . GetPendingItems < FeatureEditEntity > ( ) ;
166
+ var edits = await audits . GetPendingItems < FeatureEditEntity > ( User . Identity ) ;
114
167
AuditEntity ? audit ;
115
168
116
169
audit = edits . SingleOrDefault ( e => e . Id == id ) ;
117
170
if ( audit is null )
118
171
{
119
- var ops = await audits . GetPendingItems < FeatureOpEntity > ( ) ;
172
+ var ops = await audits . GetPendingItems < FeatureOpEntity > ( User . Identity ) ;
120
173
audit = ops . SingleOrDefault ( e => e . Id == id ) ;
121
174
}
122
175
0 commit comments