Skip to content

Commit

Permalink
Feat: add support for evidence (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage authored Sep 12, 2023
1 parent 0986eed commit f860154
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
<option *ngFor="let option of availableReasons" [value]="option">{{option}}</option>
</select>
</div>
<div class="form-group">
<label for="inputEvidence">Evidence</label>
<textarea id="inputEvidence" class="form-control" formControlName="evidence" aria-describedby="inputEvidenceDescription"></textarea>
<small id="inputEvidenceDescription">
You may optionally provide an evidence, for example links, or any other text up to 1000 characters in length.
</small>
</div>
<button type="submit" class="btn btn-primary">Censure</button>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class CensureInstanceComponent implements OnInit {
public form = new FormGroup({
instance: new FormControl<string>('', [Validators.required]),
reasons: new FormControl<string[]>([]),
evidence: new FormControl<string | null>(null),
});
public loading: boolean = true;
public availableReasons: string[] = [];
Expand Down Expand Up @@ -60,6 +61,7 @@ export class CensureInstanceComponent implements OnInit {
this.api.censureInstance(
this.form.controls.instance.value!,
this.form.controls.reasons.value ? this.form.controls.reasons.value!.join(',') : null,
this.form.controls.evidence.value,
).subscribe(response => {
if (!response.success) {
this.loading = false;
Expand Down
11 changes: 8 additions & 3 deletions src/app/censures/pages/my-censures/my-censures.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ <h3 class="card-title">Censures that {{instance.name}} <strong>has given</strong
<tr>
<th>Instance</th>
<th>Reasons</th>
<th>Evidence</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr *ngIf="guaranteed">
<td colspan="3">
<td colspan="4">
<a routerLink="/censures/censure" class="btn btn-primary">Censure an instance</a>
</td>
</tr>
<tr *ngIf="!instances.length">
<td colspan="3" *ngIf="guaranteed">You haven't put a censure on any instance yet.</td>
<td colspan="3" *ngIf="!guaranteed">No one guaranteed for this instance, you cannot put a censure on
<td colspan="4" *ngIf="guaranteed">You haven't put a censure on any instance yet.</td>
<td colspan="4" *ngIf="!guaranteed">No one guaranteed for this instance, you cannot put a censure on
others.
</td>
</tr>
Expand All @@ -39,6 +40,10 @@ <h3 class="card-title">Censures that {{instance.name}} <strong>has given</strong
<li *ngFor="let reason of instance.censureReasons">{{reason}}</li>
</ul>
</td>
<td>
<ng-container *ngIf="instance.evidence.length">{{instance.evidence}}</ng-container>
<code *ngIf="!instance.evidence.length">N/A</code>
</td>
<td>
<a routerLink="/censures/my/edit/{{instance.domain}}" type="button" class="btn btn-primary">Edit</a>
&nbsp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ <h3 class="card-title" id="censures-given">Censures given ({{censuresGiven.lengt
<tr>
<th>Instance</th>
<th>Reasons</th>
<th>Evidence</th>
</tr>
</thead>
<tbody>
Expand All @@ -138,6 +139,10 @@ <h3 class="card-title" id="censures-given">Censures given ({{censuresGiven.lengt
</ul>
<code *ngIf="!instance.censureReasons.length">N/A</code>
</td>
<td>
<ng-container *ngIf="instance.evidence.length">{{instance.evidence}}</ng-container>
<code *ngIf="!instance.evidence.length">N/A</code>
</td>
</tr>
</tbody>
</table>
Expand Down
1 change: 1 addition & 0 deletions src/app/response/instance-detail.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface InstanceDetailResponse {
censure_reasons?: string[] | null;
sysadmins: int | null;
moderators: int | null;
censure_evidence: string[];
}
2 changes: 2 additions & 0 deletions src/app/response/normalized-instance-detail.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class NormalizedInstanceDetailResponse {
public endorsements: int,
public censureReasons: string[],
public unmergedCensureReasons: string[],
public evidence: string,
public guarantor?: string | null,
) {
}
Expand Down Expand Up @@ -52,6 +53,7 @@ export class NormalizedInstanceDetailResponse {
detail.endorsements,
censureReasons,
unmerged,
detail.censure_evidence.join(', '),
detail.guarantor,
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/app/services/fediseer-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ export class FediseerApiService {
return this.sendRequest(HttpMethod.Delete, `censures/${instance}`);
}

public censureInstance(instance: string, reason: string | null): Observable<ApiResponse<SuccessResponse>> {
public censureInstance(instance: string, reason: string | null, evidence: string | null = null): Observable<ApiResponse<SuccessResponse>> {
const body: {[key: string]: string} = {};
if (reason) {
body['reason'] = reason;
}
if (evidence) {
body['evidence'] = evidence;
}
return this.sendRequest(HttpMethod.Put, `censures/${instance}`, body);
}

Expand Down

0 comments on commit f860154

Please sign in to comment.