Repository navigation
Expand file tree
/
Copy pathadmin-changes.php
More file actions
277 lines (261 loc) · 14.1 KB
/
Copy pathadmin-changes.php
File metadata and controls
277 lines (261 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
/**
* Change Request Review Page
*
* The reviewer's queue for source-data change requests (API #902).
*
* Open to global admins and to resource admins alike: the API scopes
* `/admin/change-requests` to the resources the caller administers, and
* re-checks authorization on the specific batch id for every approve and
* reject, so there is nothing for this page to filter.
*/
include_once 'includes/common.php';
include_once 'includes/messages.php';
// Require authentication - redirect to home if not logged in
if (!$authHelper->isAuthenticated) {
header('Location: index.php');
exit;
}
$isAdmin = $authHelper->hasRole('admin');
$isResourceAdmin = $authHelper->dashboardScopes()['is_resource_admin'];
// Anyone who administers nothing has nothing to review here.
if (!$isAdmin && !$isResourceAdmin) {
header('Location: admin-dashboard.php');
exit;
}
// The GitHub repository the phase 2 publisher opens pull requests against, so a
// settled batch's `pr_number` can be linked. Empty (the number is then shown bare)
// unless the deployment names a well-formed "owner/repo".
$sourceDataRepo = trim((string) ( $_ENV['SOURCEDATA_REPOSITORY'] ?? '' ));
$sourceDataRepoUrl = preg_match('#^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$#', $sourceDataRepo) === 1
? 'https://github.com/' . $sourceDataRepo
: '';
?>
<!doctype html>
<html lang="<?php echo htmlspecialchars($i18n->LOCALE, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>">
<head>
<title><?php
$changesTitle = _('Change Request Review');
$calendarTitle = _('Catholic Liturgical Calendar');
echo htmlspecialchars($changesTitle, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
echo ' - ';
echo htmlspecialchars($calendarTitle, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></title>
<?php include_once('./layout/head.php'); ?>
</head>
<body class="sb-nav-fixed">
<?php include_once('./layout/header.php'); ?>
<h1 class="h3 mb-4 text-black" style="--bs-text-opacity: .6;">
<i class="fas fa-code-pull-request me-2"></i><?php
echo htmlspecialchars(_('Change Request Review'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?>
</h1>
<p class="text-muted mb-4"><?php
// phpcs:ignore Generic.Files.LineLength
$pageDesc = _('Review the source data changes proposed for the calendars you administer. Approving a change request is the only human gate before it is published, so read what it proposes before deciding.');
echo htmlspecialchars($pageDesc, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?></p>
<!-- Stats Cards -->
<div class="row mb-4">
<div class="col-md-3 mb-3 mb-md-0">
<div class="card border-warning h-100">
<div class="card-body text-center">
<i class="fas fa-hourglass-half fa-2x text-warning mb-2"></i>
<h4 class="mb-0" id="submittedCount">
<span class="spinner-border spinner-border-sm" role="status"></span>
</h4>
<small class="text-muted"><?php echo htmlspecialchars(_('Submitted'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></small>
</div>
</div>
</div>
<div class="col-md-3 mb-3 mb-md-0">
<div class="card border-success h-100">
<div class="card-body text-center">
<i class="fas fa-check-circle fa-2x text-success mb-2"></i>
<h4 class="mb-0" id="approvedCount">
<span class="spinner-border spinner-border-sm" role="status"></span>
</h4>
<small class="text-muted"><?php echo htmlspecialchars(_('Approved'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></small>
</div>
</div>
</div>
<div class="col-md-3 mb-3 mb-md-0">
<div class="card border-danger h-100">
<div class="card-body text-center">
<i class="fas fa-times-circle fa-2x text-danger mb-2"></i>
<h4 class="mb-0" id="rejectedCount">
<span class="spinner-border spinner-border-sm" role="status"></span>
</h4>
<small class="text-muted"><?php echo htmlspecialchars(_('Rejected'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></small>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card border-secondary h-100">
<div class="card-body text-center">
<i class="fas fa-undo fa-2x text-secondary mb-2"></i>
<h4 class="mb-0" id="withdrawnCount">
<span class="spinner-border spinner-border-sm" role="status"></span>
</h4>
<small class="text-muted"><?php echo htmlspecialchars(_('Withdrawn'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?></small>
</div>
</div>
</div>
</div>
<!-- Filter Tabs -->
<ul class="nav nav-tabs mb-3" id="statusTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="submitted-tab" data-bs-toggle="tab" data-bs-target="#submitted-panel"
type="button" role="tab" aria-controls="submitted-panel" aria-selected="true">
<i class="fas fa-hourglass-half me-1"></i><?php echo htmlspecialchars(_('Submitted'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
<span class="badge bg-warning text-dark ms-1" id="pendingBadge">0</span>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="approved-tab" data-bs-toggle="tab" data-bs-target="#approved-panel"
type="button" role="tab" aria-controls="approved-panel" aria-selected="false">
<i class="fas fa-check-circle me-1"></i><?php echo htmlspecialchars(_('Approved'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="rejected-tab" data-bs-toggle="tab" data-bs-target="#rejected-panel"
type="button" role="tab" aria-controls="rejected-panel" aria-selected="false">
<i class="fas fa-times-circle me-1"></i><?php echo htmlspecialchars(_('Rejected'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="withdrawn-tab" data-bs-toggle="tab" data-bs-target="#withdrawn-panel"
type="button" role="tab" aria-controls="withdrawn-panel" aria-selected="false">
<i class="fas fa-undo me-1"></i><?php echo htmlspecialchars(_('Withdrawn'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</li>
<li class="nav-item ms-auto">
<button class="btn btn-outline-primary btn-sm" id="refreshBtn" data-requires-auth>
<i class="fas fa-sync-alt me-1"></i><?php echo htmlspecialchars(_('Refresh'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</li>
</ul>
<!-- Tab Content -->
<div class="tab-content" id="statusTabContent">
<div class="tab-pane fade show active" id="submitted-panel" role="tabpanel" aria-labelledby="submitted-tab">
<div class="card shadow">
<div class="card-body" id="submittedChangesBody">
<div class="text-center text-muted">
<i class="fas fa-spinner fa-spin me-2"></i><?php echo htmlspecialchars(_('Loading...'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="approved-panel" role="tabpanel" aria-labelledby="approved-tab">
<div class="card shadow">
<div class="card-body" id="approvedChangesBody">
<div class="text-center text-muted">
<i class="fas fa-spinner fa-spin me-2"></i><?php echo htmlspecialchars(_('Loading...'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="rejected-panel" role="tabpanel" aria-labelledby="rejected-tab">
<div class="card shadow">
<div class="card-body" id="rejectedChangesBody">
<div class="text-center text-muted">
<i class="fas fa-spinner fa-spin me-2"></i><?php echo htmlspecialchars(_('Loading...'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="withdrawn-panel" role="tabpanel" aria-labelledby="withdrawn-tab">
<div class="card shadow">
<div class="card-body" id="withdrawnChangesBody">
<div class="text-center text-muted">
<i class="fas fa-spinner fa-spin me-2"></i><?php echo htmlspecialchars(_('Loading...'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</div>
</div>
</div>
</div>
</div>
<div class="d-flex gap-2 mt-4">
<a href="admin-dashboard.php" class="btn btn-outline-secondary" data-requires-auth>
<i class="fas fa-arrow-left me-2"></i><?php echo htmlspecialchars(_('Back to Dashboard'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</a>
<a href="change-requests.php" class="btn btn-outline-primary" data-requires-auth>
<i class="fas fa-user-edit me-2"></i><?php echo htmlspecialchars(_('Your Change Requests'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</a>
</div>
<!-- Review Modal -->
<div class="modal fade" id="reviewModal" tabindex="-1" aria-labelledby="reviewModalLabel">
<div class="modal-dialog modal-xl modal-dialog-scrollable">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="reviewModalLabel">
<i class="fas fa-code-pull-request me-2"></i><?php
echo htmlspecialchars(_('Review Change Request'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?>
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="<?php echo htmlspecialchars(_('Close'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>"></button>
</div>
<div class="modal-body">
<div id="changeRequestDetails">
<!-- Filled by JavaScript -->
</div>
<hr>
<div class="mb-3" id="notesSection">
<label for="reviewNotes" class="form-label"><?php
$reasonLabel = _('Reason for rejection');
$optionalLabel = _('optional');
echo htmlspecialchars($reasonLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?> <span class="text-muted">(<?php
echo htmlspecialchars($optionalLabel, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?>)</span></label>
<?php $placeholder = _('The submitter will be shown this reason.'); ?>
<textarea class="form-control" id="reviewNotes" rows="3"
placeholder="<?php echo htmlspecialchars($placeholder, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>"></textarea>
</div>
<div id="modalAlerts"></div>
</div>
<div class="modal-footer" id="modalFooter">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
<i class="fas fa-times me-1"></i><?php echo htmlspecialchars(_('Cancel'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
<button type="button" class="btn btn-danger d-none" id="rejectBtn" data-requires-auth>
<i class="fas fa-times-circle me-1"></i><?php echo htmlspecialchars(_('Reject'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
<button type="button" class="btn btn-success d-none" id="approveBtn" data-requires-auth>
<i class="fas fa-check-circle me-1"></i><?php echo htmlspecialchars(_('Approve'), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); ?>
</button>
</div>
</div>
</div>
</div>
<!-- Config must be defined BEFORE footer.php, which auto-loads admin-changes.js -->
<?php
/** @var array<string, mixed> $changeRequestI18n */
$changeRequestI18n = include './includes/change-request-i18n.php';
$adminChangesI18n = array_merge($changeRequestI18n, [
'submittedBy' => _('Submitted by'),
'outcome' => _('Outcome'),
'review' => _('Review'),
'reviewDecision' => _('Reviewer decision'),
'rejectedReason' => _('Reason'),
'noPendingChanges' => _('No change requests are waiting for review. All caught up!'),
'noChangeRequests' => _('No change requests found.'),
'failedToLoad' => _('Failed to load change requests. Please try again later.'),
'processing' => _('Processing...'),
'approveSuccess' => _('Change request approved.'),
'rejectSuccess' => _('Change request rejected.'),
'failedToProcess' => _('Failed to process this change request. Please try again.'),
'alreadyDecided' => _('This change request was already decided by someone else. Reloading the list.'),
]);
?>
<script>
window.AdminChangesConfig = {
apiUrl: <?php echo json_encode($apiBaseUrl); ?>,
locale: <?php echo json_encode(str_replace('_', '-', $i18n->LOCALE)); ?>,
repoUrl: <?php echo json_encode($sourceDataRepoUrl); ?>,
i18n: <?php echo json_encode($adminChangesI18n); ?>
};
</script>
<?php include_once('./layout/footer.php'); ?>
</body>
</html>