forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorProjectUpdateController.php
120 lines (100 loc) · 3.31 KB
/
PhabricatorProjectUpdateController.php
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
<?php
final class PhabricatorProjectUpdateController
extends PhabricatorProjectController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$action = $request->getURIData('action');
$capabilities = array(
PhabricatorPolicyCapability::CAN_VIEW,
);
switch ($action) {
case 'join':
$capabilities[] = PhabricatorPolicyCapability::CAN_JOIN;
break;
case 'leave':
break;
default:
return new Aphront404Response();
}
$project = id(new PhabricatorProjectQuery())
->setViewer($viewer)
->withIDs(array($id))
->needMembers(true)
->requireCapabilities($capabilities)
->executeOne();
if (!$project) {
return new Aphront404Response();
}
$done_uri = "/project/members/{$id}/";
if (!$project->supportsEditMembers()) {
$copy = pht('Parent projects and milestones do not support adding '.
'members. You can add members directly to any non-parent subproject.');
return $this->newDialog()
->setTitle(pht('Unsupported Project'))
->appendParagraph($copy)
->addCancelButton($done_uri);
}
if ($request->isFormPost()) {
$edge_action = null;
switch ($action) {
case 'join':
$edge_action = '+';
break;
case 'leave':
$edge_action = '-';
break;
}
$type_member = PhabricatorProjectProjectHasMemberEdgeType::EDGECONST;
$member_spec = array(
$edge_action => array($viewer->getPHID() => $viewer->getPHID()),
);
$xactions = array();
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', $type_member)
->setNewValue($member_spec);
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($done_uri);
}
$is_locked = $project->getIsMembershipLocked();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
$can_leave = ($can_edit || !$is_locked);
$button = null;
if ($action == 'leave') {
if ($can_leave) {
$title = pht('Leave Project');
$body = pht(
'Your tremendous contributions to this project will be sorely '.
'missed. Are you sure you want to leave?');
$button = pht('Leave Project');
} else {
$title = pht('Membership Locked');
$body = pht(
'Membership for this project is locked. You can not leave.');
}
} else {
$title = pht('Join Project');
$body = pht(
'Join this project? You will become a member and enjoy whatever '.
'benefits membership may confer.');
$button = pht('Join Project');
}
$dialog = $this->newDialog()
->setTitle($title)
->appendParagraph($body)
->addCancelButton($done_uri);
if ($button) {
$dialog->addSubmitButton($button);
}
return $dialog;
}
}