1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-06 03:48:28 +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', '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' => 'ponder-comment-table-css' =>
array( array(
'uri' => '/res/4aa4b865/rsrc/css/application/ponder/comments.css', 'uri' => '/res/4aa4b865/rsrc/css/application/ponder/comments.css',

View file

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

View file

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

View file

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