1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-28 23:48:19 +01:00

Improve messaging of special policy rules in applications

Summary: Ref T603. When the user encounters an action which is controlled by a special policy rule in the application, make it easier for applications to show the user what policy controls the action and what the setting is. I took this about halfway before and left a TODO, but turn it into something more useful.

Test Plan: See screenshots.

Reviewers: btrahan, chad

Reviewed By: chad

CC: chad, aran

Maniphest Tasks: T603

Differential Revision: https://secure.phabricator.com/D7265
This commit is contained in:
epriestley 2013-10-09 13:52:04 -07:00
parent 45f38c549b
commit 3147a6ca57
6 changed files with 85 additions and 24 deletions

View file

@ -3884,6 +3884,15 @@ celerity_register_resource_map(array(
),
'disk' => '/rsrc/css/phui/phui-workpanel-view.css',
),
'policy-css' =>
array(
'uri' => '/res/ebb12aa0/rsrc/css/application/policy/policy.css',
'type' => 'css',
'requires' =>
array(
),
'disk' => '/rsrc/css/application/policy/policy.css',
),
'ponder-comment-table-css' =>
array(
'uri' => '/res/4aa4b865/rsrc/css/application/ponder/comments.css',

View file

@ -364,9 +364,46 @@ abstract class PhabricatorController extends AphrontController {
$capability);
}
protected function explainApplicationCapability($capability, $message) {
// TODO: Render a link to get more information.
return $message;
protected function explainApplicationCapability(
$capability,
$positive_message,
$negative_message) {
$can_act = $this->hasApplicationCapability($capability);
if ($can_act) {
$message = $positive_message;
$icon_name = 'enable-grey';
} else {
$message = $negative_message;
$icon_name = 'lock';
}
$icon = id(new PHUIIconView())
->setSpriteSheet(PHUIIconView::SPRITE_ICONS)
->setSpriteIcon($icon_name);
require_celerity_resource('policy-css');
$phid = $this->getCurrentApplication()->getPHID();
$explain_uri = "/policy/explain/{$phid}/{$capability}/";
$message = phutil_tag(
'div',
array(
'class' => 'policy-capability-explanation',
),
array(
$icon,
javelin_tag(
'a',
array(
'href' => $explain_uri,
'sigil' => 'workflow',
),
$message),
));
return array($can_act, $message);
}
}

View file

@ -17,9 +17,6 @@ final class HeraldNewController extends HeraldController {
$this->requireApplicationCapability(
HeraldCapabilityCreateRules::CAPABILITY);
$can_global = $this->hasApplicationCapability(
HeraldCapabilityManageGlobalRules::CAPABILITY);
$content_type_map = HeraldAdapter::getEnabledAdapterMap($user);
if (empty($content_type_map[$this->contentType])) {
$this->contentType = head_key($content_type_map);
@ -37,13 +34,10 @@ final class HeraldNewController extends HeraldController {
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL,
)) + $rule_type_map;
if (!$can_global) {
$global_link = $this->explainApplicationCapability(
HeraldCapabilityManageGlobalRules::CAPABILITY,
pht('You do not have permission to create or manage global rules.'));
} else {
$global_link = null;
}
list($can_global, $global_link) = $this->explainApplicationCapability(
HeraldCapabilityManageGlobalRules::CAPABILITY,
pht('You have permission to create and manage global rules.'),
pht('You do not have permission to create or manage global rules.'));
$captions = array(
HeraldRuleTypeConfig::RULE_TYPE_PERSONAL =>
@ -52,15 +46,12 @@ final class HeraldNewController extends HeraldController {
'only affect you. Personal rules only trigger for objects you have '.
'permission to see.'),
HeraldRuleTypeConfig::RULE_TYPE_GLOBAL =>
phutil_implode_html(
phutil_tag('br'),
array_filter(
array(
pht(
'Global rules notify anyone about events. Global rules can '.
'bypass access control policies and act on any object.'),
$global_link,
))),
array(
pht(
'Global rules notify anyone about events. Global rules can '.
'bypass access control policies and act on any object.'),
$global_link,
),
);
$radio = id(new AphrontFormRadioButtonControl())

View file

@ -63,8 +63,14 @@ final class PhabricatorPolicyExplainController
$auto_info = phutil_tag('ul', array(), $auto_info);
}
$capability_name = $capability;
$capobj = PhabricatorPolicyCapability::getCapabilityByKey($capability);
if ($capobj) {
$capability_name = $capobj->getCapabilityName();
}
$content = array(
pht('Users with the "%s" capability:', "Can View"),
pht('Users with the "%s" capability:', $capability_name),
$auto_info,
);

View file

@ -50,7 +50,7 @@ final class AphrontFormRadioButtonControl extends AphrontFormControl {
),
$button['label']);
if (strlen($button['caption'])) {
if ($button['caption']) {
$label = hsprintf(
'%s<div class="aphront-form-radio-caption">%s</div>',
$label,

View file

@ -0,0 +1,18 @@
/**
* @provides policy-css
*/
.policy-capability-explanation .phui-icon-view {
display: inline-block;
vertical-align: text-top;
}
.policy-capability-explanation {
margin: 8px 0 0;
}
.policy-capability-explanation a {
line-height: 14px;
margin-left: 4px;
color: {$bluetext};
}