@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class PhabricatorProjectLockController
4 extends PhabricatorProjectController {
5
6 public function shouldAllowPublic() {
7 return true;
8 }
9
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12
13 $this->requireApplicationCapability(
14 ProjectCanLockProjectsCapability::CAPABILITY);
15
16 $id = $request->getURIData('id');
17 $project = id(new PhabricatorProjectQuery())
18 ->setViewer($viewer)
19 ->withIDs(array($id))
20 ->requireCapabilities(
21 array(
22 PhabricatorPolicyCapability::CAN_VIEW,
23 PhabricatorPolicyCapability::CAN_EDIT,
24 ))
25 ->executeOne();
26 if (!$project) {
27 return new Aphront404Response();
28 }
29
30 $done_uri = "/project/members/{$id}/";
31
32 if (!$project->supportsEditMembers()) {
33 return $this->newDialog()
34 ->setTitle(pht('Membership Immutable'))
35 ->appendChild(
36 pht('This project does not support editing membership.'))
37 ->addCancelButton($done_uri);
38 }
39
40 $is_locked = $project->getIsMembershipLocked();
41
42 if ($request->isFormPost()) {
43 $xactions = array();
44
45 if ($is_locked) {
46 $new_value = 0;
47 } else {
48 $new_value = 1;
49 }
50
51 $xactions[] = id(new PhabricatorProjectTransaction())
52 ->setTransactionType(
53 PhabricatorProjectLockTransaction::TRANSACTIONTYPE)
54 ->setNewValue($new_value);
55
56 $editor = id(new PhabricatorProjectTransactionEditor())
57 ->setActor($viewer)
58 ->setContentSourceFromRequest($request)
59 ->setContinueOnNoEffect(true)
60 ->setContinueOnMissingFields(true)
61 ->applyTransactions($project, $xactions);
62
63 return id(new AphrontRedirectResponse())->setURI($done_uri);
64 }
65
66 if ($project->getIsMembershipLocked()) {
67 $title = pht('Unlock Project');
68 $body = pht(
69 'If you unlock this project, members will be free to leave.');
70 $button = pht('Unlock Project');
71 } else {
72 $title = pht('Lock Project');
73 $body = pht(
74 'If you lock this project, members will be prevented from '.
75 'leaving it.');
76 $button = pht('Lock Project');
77 }
78
79 return $this->newDialog()
80 ->setTitle($title)
81 ->appendParagraph($body)
82 ->addSubmitbutton($button)
83 ->addCancelButton($done_uri);
84 }
85
86}