Skip to content
Permalink
Browse files

Make sure all existing object privileges are shown correctly in asgard

  • Loading branch information...
flack committed Mar 27, 2019
1 parent 31a7a6e commit 7a245290d3203ba4da47805d5b7ccc3591a6596d
@@ -533,6 +533,7 @@ private function _sync_from_db_object()
$this->assignee = $this->__privilege_object->assignee;
$this->classname = $this->__privilege_object->classname;
$this->value = $this->__privilege_object->value;
$this->guid = $this->__privilege_object->guid;
}
/**
@@ -179,6 +179,10 @@ private function process_assignees(array $assignees, schemadb $schemadb)
$fields = $schemadb->get('privileges')->get('fields');
foreach ($assignees as $assignee => $label) {
$classname = '';
if (strpos($assignee, '/')) {
list($assignee, $classname) = explode('/', $assignee, 2);
}
foreach ($this->_privileges as $privilege) {
$privilege_components = explode(':', $privilege);
if ( $privilege_components[0] == 'midcom'
@@ -194,18 +198,20 @@ private function process_assignees(array $assignees, schemadb $schemadb)
$header_items[$privilege_label] = " <th scope=\"col\" class=\"{$privilege_components[1]}\"><span>" . $this->_l10n->get($privilege_label) . "</span></th>\n";
}
$fields[str_replace([':', '.'], '_', $assignee . '_' . $privilege)] = [
$fields[str_replace([':', '.'], '_', $assignee . $classname . '__' . $privilege)] = [
'title' => $privilege_label,
'storage' => null,
'type' => 'privilege',
'type_config' => [
'privilege_name' => $privilege,
'assignee' => $assignee,
'assignee' => $assignee,
'classname' => $classname
],
'widget' => 'privilegeselection'
];
}
}
$schemadb->get('privileges')->set('fields', $fields);
$header .= " <th scope=\"col\" class=\"assignee_name\"><span>&nbsp;</span></th>\n";
@@ -225,6 +231,9 @@ private function load_assignees()
$existing_privileges[] = new midcom_core_privilege(['assignee' => $this->additional_assignee]);
}
foreach ($existing_privileges as $privilege) {
if (!in_array($privilege->privilegename, $this->_privileges)) {
$this->_privileges[] = $privilege->privilegename;
}
if ($privilege->is_magic_assignee()) {
// This is a magic assignee
$label = $this->_l10n->get($privilege->assignee);
@@ -239,21 +248,21 @@ private function load_assignees()
}
}
$assignees[$privilege->assignee] = $label;
if ($privilege->classname) {
$label .= ' / ' . $privilege->classname;
$assignees[$privilege->assignee . '/' . $privilege->classname] = $label;
} else {
$assignees[$privilege->assignee] = $label;
}
$key = str_replace(':', '_', $privilege->assignee);
$key = str_replace(':', '_', $privilege->assignee) . $privilege->classname;
if (!isset($this->_row_labels[$key])) {
$this->_row_labels[$key] = $label;
}
}
return $assignees;
}
public function get_schema_name()
{
return 'privileges';
}
/**
* Object editing view
*
@@ -20,7 +20,7 @@
echo '<th class="row_value assignee_name"><span>' . $label . '</span></th>';
$started = false;
foreach ($data['form']->children as $name => $child) {
if (substr($name, 0, strlen($identifier)) !== $identifier) {
if (substr($name, 0, strlen($identifier) + 2) !== $identifier . '__') {
if ($started) {
echo '<td class="row_value row_actions">';
echo '<div class="actions" id="privilege_row_actions_' . $identifier . '"></div>';
@@ -66,6 +66,10 @@ private function get_effective_value(array $options, FormInterface $form)
}
if ($options['assignee'] == 'SELF') {
if (midcom::get()->dbfactory->is_a($object, 'midgard_group')) {
$privilege = $object->get_privilege($options['privilege_name'], $options['assignee'], $options['classname']);
if ($privilege->guid) {
return $privilege->value === MIDCOM_PRIVILEGE_ALLOW;
}
// There's no sane way to query group privileges in auth right now, so we only return defaults
$defaults = midcom::get()->auth->acl->get_default_privileges();
return $defaults[$options['privilege_name']] === MIDCOM_PRIVILEGE_ALLOW;
@@ -303,6 +303,7 @@ public function choice_widget_collapsed(FormView $view, array $data)
$string = $this->get_view_renderer()->choice_widget_collapsed($view, $data);
return $string . $this->renderer->block($view, 'form_widget_simple', ['type' => "hidden"]);
}
$string = '<select ';
if ( $data['required']
&& null === $data['placeholder']
@@ -377,7 +378,10 @@ public function choice_widget_options(FormView $view, array $data)
$choice->attr['value'] = $choice->value;
if ($data['is_selected']($choice->value, $data['value'])) {
$choice->attr['selected'] = 'selected';
} else {
unset($choice->attr['selected']);
}
$string .= '<option ' . $this->attributes($choice->attr);
$string .= '>' . $this->renderer->humanize($choice->label) . '</option>';
}

0 comments on commit 7a24529

Please sign in to comment.
You can’t perform that action at this time.