@@ -16,7 +16,7 @@ public class AdminController(ConfigurationOptions options, HangfireLauncherServi
1616 /// Enqueues a job that updates xmldoc content from the latest release/pre-release tags.
1717 /// </summary>
1818 /// <returns>The unique identifier of the enqueued job.</returns>
19- [ Authorize ( "github" , Roles = RDConstants . AdminRole ) ]
19+ [ Authorize ( "github" , Roles = RDConstants . Roles . AdminRole ) ]
2020 [ HttpPost ( "admin/update/xmldoc" ) ]
2121 public IActionResult UpdateXmldocContent ( )
2222 {
@@ -28,43 +28,96 @@ public IActionResult UpdateXmldocContent()
2828 /// Enqueues a job that gets the latest release/pre-release tags and their respective assets, and updates the installer download stats.
2929 /// </summary>
3030 /// <returns>The unique identifier of the enqueued job.</returns>
31- [ Authorize ( "github" , Roles = RDConstants . AdminRole ) ]
31+ [ Authorize ( "github" , Roles = RDConstants . Roles . AdminRole ) ]
3232 [ HttpPost ( "admin/update/tags" ) ]
3333 public IActionResult UpdateTagMetadata ( )
3434 {
3535 var jobId = hangfire . UpdateTagMetadata ( ) ;
3636 return Ok ( jobId ) ;
3737 }
3838
39- [ Authorize ( "github" , Roles = RDConstants . AdminRole ) ]
39+ [ Authorize ( "github" , Roles = RDConstants . Roles . AdminRole ) ]
4040 [ HttpPost ( "admin/cache/clear" ) ]
4141 public IActionResult ClearCache ( )
4242 {
4343 cache . Clear ( ) ;
4444 return Ok ( ) ;
4545 }
4646
47- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
47+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } , { RDConstants . Roles . WriterRole } ") ]
4848 [ HttpGet ( "admin/audits/pending" ) ]
4949 public async Task < IActionResult > GetPendingAudits ( )
5050 {
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 ) ;
5353
5454 return Ok ( new { edits = edits . ToArray ( ) , other = ops . ToArray ( ) } ) ;
5555 }
5656
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}" ) ]
59112 public async Task < IActionResult > GetPendingAudits ( [ FromRoute ] int featureId )
60113 {
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 ) ;
63116
64117 return Ok ( new { edits = edits . ToArray ( ) , other = ops . ToArray ( ) } ) ;
65118 }
66119
67- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
120+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ") ]
68121 [ HttpPost ( "admin/audits/approve/{id}" ) ]
69122 public async Task < IActionResult > ApprovePendingAudit ( [ FromRoute ] int id )
70123 {
@@ -74,13 +127,13 @@ public async Task<IActionResult> ApprovePendingAudit([FromRoute] int id)
74127 return Unauthorized ( "User identity is not available." ) ;
75128 }
76129
77- var edits = await audits . GetPendingItems < FeatureEditEntity > ( ) ;
130+ var edits = await audits . GetPendingItems < FeatureEditEntity > ( User . Identity ) ;
78131 AuditEntity ? audit ;
79132
80133 audit = edits . SingleOrDefault ( e => e . Id == id ) ;
81134 if ( audit is null )
82135 {
83- var ops = await audits . GetPendingItems < FeatureOpEntity > ( ) ;
136+ var ops = await audits . GetPendingItems < FeatureOpEntity > ( User . Identity ) ;
84137 audit = ops . SingleOrDefault ( e => e . Id == id ) ;
85138 }
86139
@@ -100,7 +153,7 @@ public async Task<IActionResult> ApprovePendingAudit([FromRoute] int id)
100153 return Ok ( "Operation was approved successfully." ) ;
101154 }
102155
103- [ Authorize ( "github" , Roles = $ "{ RDConstants . AdminRole } ,{ RDConstants . ReviewerRole } ") ]
156+ [ Authorize ( "github" , Roles = $ "{ RDConstants . Roles . AdminRole } ,{ RDConstants . Roles . ReviewerRole } ") ]
104157 [ HttpPost ( "admin/audits/reject/{id}" ) ]
105158 public async Task < IActionResult > RejectPendingAudit ( [ FromRoute ] int id )
106159 {
@@ -110,13 +163,13 @@ public async Task<IActionResult> RejectPendingAudit([FromRoute] int id)
110163 return Unauthorized ( "User identity is not available." ) ;
111164 }
112165
113- var edits = await audits . GetPendingItems < FeatureEditEntity > ( ) ;
166+ var edits = await audits . GetPendingItems < FeatureEditEntity > ( User . Identity ) ;
114167 AuditEntity ? audit ;
115168
116169 audit = edits . SingleOrDefault ( e => e . Id == id ) ;
117170 if ( audit is null )
118171 {
119- var ops = await audits . GetPendingItems < FeatureOpEntity > ( ) ;
172+ var ops = await audits . GetPendingItems < FeatureOpEntity > ( User . Identity ) ;
120173 audit = ops . SingleOrDefault ( e => e . Id == id ) ;
121174 }
122175
0 commit comments