Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified scope handling. #150

Merged
merged 2 commits into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/gocdb_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,11 @@
<!--<regex>/^[a-zA-Z0-9\-\._\(\)\[\],;+:\/'"\s]*$/</regex>-->
<regex>/^[^`'\";&lt;&gt;]+$/</regex>
</field>
<field>
<fname>RESERVED</fname>
<length>1</length>
<regex>/^[01]$/</regex>
</field>
</entity>
<!-- ========================================================== -->
<entity>
Expand Down
27 changes: 0 additions & 27 deletions config/local_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,6 @@
<service_group>1</service_group>
</minimum_scopes>

<!--
Specify a list of RESERVED scope tag names:
- New Reserved tags can only be directly assigned to resources by the gocdb-admins
(resources include NGIs, Sites, Services, SGs but not Projects - don't currently need to tag projects)
- When creating a new child resource (e.g. a child Site or child Service),
the scopes that are assigned to the parent are automatically inherited and assigned to the child.
- Reserved tags assigned to a resource are optional.
- Users can reapply Reserved tags to a resource ONLY if the tag can be
inherited from the parent ScopedEntity (parents include NGIs/Sites).
- For Sites: If a Reserved tag is removed from a Site, then the same tag is also removed
from all the child services - a Service can't have a reserved tag that
is not supported by its parent Site.
- For NGIs: If a Reserved tag is removed from an NGI, then the same tag is NOT
removed from all the child Sites - this is intentionally different from the Site->Service relationship.
-->
<reserved_scopes>
<scope>wlcg</scope>
<scope>tier1</scope>
<scope>tier2</scope>
<scope>alice</scope>
<scope>atlas</scope>
<scope>cms</scope>
<scope>lhcb</scope>
<scope>elixir</scope>
<scope>FedCloud</scope>
</reserved_scopes>

<!-- Define the max amount of extensions a user can define when using the extensions feature -->
<extensions>
<max>20</max>
Expand Down
10 changes: 6 additions & 4 deletions htdocs/web_portal/controllers/admin/edit_scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function draw() {

$params = array('Name' => $scope->getName(),
'Id' => $scope->getId(),
'Description' => $scope->getDescription());
'Description' => $scope->getDescription(),
'Reserved' => $scope->getReserved());

//show the add service type view
show_view("admin/edit_scope.php", $params, "Edit Scope");
Expand All @@ -83,12 +84,13 @@ function submit() {
$user = \Factory::getUserService()->getUserByPrinciple($dn);

try {
//function will through error if user does not have the correct permissions
//function will throw an error if user does not have the correct permissions
$scope = $serv->editScope($scope, $values, $user);
$params = array('Name' => $scope->getName(),
'ID'=> $scope->getId(),
'Description' => $scope->getDescription());
show_view("admin/edited_scope.php", $params, $params['Name']. " succesffully updated");
'Description' => $scope->getDescription(),
'Reserved' => $scope->getReserved());
show_view("admin/edited_scope.php", $params, $params['Name']. " successfully updated");
} catch (Exception $e) {
show_view('error.php', $e->getMessage());
die();
Expand Down
1 change: 1 addition & 0 deletions htdocs/web_portal/controllers/scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function view_scope() {
$params['Name'] = $scope->getName();
$params['Description'] = $scope->getDescription();
$params['ID'] = $scope->getId();
$params['Reserved'] = $scope->getReserved();
$params['NGIs'] = $serv->getNgisFromScope($scope);
$params['Sites'] = $serv->getSitesFromScope($scope);
$params['ServiceGroups'] = $serv->getServiceGroupsFromScope($scope);
Expand Down
8 changes: 6 additions & 2 deletions htdocs/web_portal/controllers/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function getEntityScopesAsJSON2($targetScopedEntity = null, $parentScopedEntity
$parentScopes = $parentScopedEntity->getScopes()->toArray();
}

$reservedScopeNames = \Factory::getConfigService()->getReservedScopeList();
// $reservedScopeNames = \Factory::getConfigService()->getReservedScopeList();
$allScopes = \Factory::getScopeService()->getScopes();
$optionalScopeIds = array();
$reservedOptionalScopeIds = array();
Expand All @@ -139,7 +139,7 @@ function getEntityScopesAsJSON2($targetScopedEntity = null, $parentScopedEntity
}

// Is scope tag in the reserved list ?
if(in_array($scope->getName(), $reservedScopeNames)){
if($scope->getReserved()){
// A reserved scope tag:
if($parentChecked || $targetChecked){
if($parentChecked){
Expand Down Expand Up @@ -656,6 +656,10 @@ function getDateFormat() {
function getScopeDataFromWeb() {
$scopeData ['Name'] = trim($_REQUEST ['Name']);
$scopeData ['Description'] = trim($_REQUEST ['Description']);
// 'Reserved' value is a checkbox ==>> absent if not checked
if (array_key_exists('Reserved', $_REQUEST)){
$scopeData ['Reserved'] = ($_REQUEST ['Reserved'] == '1');
}
if (array_key_exists('Id', $_REQUEST)){
$scopeData ['Id'] = $_REQUEST ['Id'];
}
Expand Down
11 changes: 5 additions & 6 deletions htdocs/web_portal/css/web_portal.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,13 @@
margin-bottom: 0.3em;
}

.input_input_text,
.input_input_date,
.input_input_check {
margin-left: 2em;
.input_input_checkbox, .input_input_date, .input_input_text {
margin-bottom: 1em;
margin-left: 2em !important;
}

.input_input_text,
.input_input_date {

.input_input_text, .input_input_date {
width: 90%;
margin-bottom: 1em;
}
Expand Down
2 changes: 2 additions & 0 deletions htdocs/web_portal/views/admin/add_scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<input type="text" value="" name="Name" class="input_input_text">
<span class="input_name">Description</span>
<input type="text" value="" name="Description" class="input_input_text">
<span class="input_name">Reserved - check to create a reserved scope</span>
<input type="checkbox" value="1" <?php echo (($params['Reserved'] == true) ? 'checked' : ''); ?> name="Reserved" class="input_input_checkbox">
<br />
<input type="submit" value="Add Scope" class="input_button">
</form>
Expand Down
3 changes: 2 additions & 1 deletion htdocs/web_portal/views/admin/edit_scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<input type="text" value="<?php xecho($params['Name']) ?>" name="Name" class="input_input_text">
<span class="input_name">Description</span>
<input type="text" value="<?php xecho($params['Description']) ?>" name="Description" class="input_input_text">

<span class="input_name">Reserved - check to set scope as Reserved</span>
<input type="checkbox" value="1" <?php echo (($params['Reserved'] == true) ? 'checked' : ''); ?> name="Reserved" class="input_input_checkbox">
<br />
<input class="input_input_hidden" type="hidden" name="Id" value="<?php echo $params['Id'] ?>" />
<br />
Expand Down
10 changes: 6 additions & 4 deletions htdocs/web_portal/views/admin/edited_scope.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<div class="rightPageContainer">
<h1 class="Success">Success</h1><br />
<p>
<a href="index.php?Page_Type=Scope&amp;id=<?php echo $params['ID']?>">
<?php xecho($params['Name'])?>
</a> has been successfully edited as follows:
<a href="index.php?Page_Type=Scope&amp;id=<?php echo $params['ID']?>">
<?php xecho($params['Name'])?>
</a> has been successfully edited as follows:
</p>
<p>
Name: <?php xecho($params['Name'])?>
<br />
Description: <?php xecho($params['Description'])?>
<br />
Reserved scope: <?php xecho(($params['Reserved'] == true) ? 'Yes' : 'No') ?>
<br />
</p>
<p>
<a href="index.php?Page_Type=Admin_Edit_Scope&amp;id=<?php echo $params['ID']?>">
Expand All @@ -17,4 +20,3 @@
</p>
</div>


4 changes: 4 additions & 0 deletions htdocs/web_portal/views/scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$description = $params['Description'];
$ngis = $params['NGIs'];
$ngiCount = count($ngis);
$reserved = $params['Reserved'];
$sites = $params['Sites'];
$siteCount = count($sites);
$serviceGroups = $params['ServiceGroups'];
Expand All @@ -19,6 +20,9 @@
<div style="float: left; width: 50em;">
<h1 style="float: left; margin-left: 0em;">Scope: <?php echo $name?></h1>
<span style="clear: both; float: left; padding-bottom: 0.4em;"><?php echo $description ?></span>
<span style="clear: both; float: left; padding-bottom: 0.4em;">
This scope is <?php echo(($reserved) ? 'reserved' : 'not reserved') ?>.
</span>
<span style="clear: both; float: left; padding-bottom: 0.4em;">
<?php if($totalCount>0):?>
In total, there are <?php if($totalCount==1){echo "is";}else{echo "are";}?>
Expand Down
16 changes: 13 additions & 3 deletions htdocs/web_portal/views/scopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,18 @@
</span>
</div>
</td>
<td class="site_table"><?php xecho($scope->getDescription()); ?></td>
<td class="site_table"><?= in_array($scope, $params['reservedScopes']) ? '&check;': '&cross;';?></td>
<td class="site_table" style="width: 60%">
<div style="background-color: inherit;">
<span style="vertical-align: middle;">
<?php xecho($scope->getDescription()); ?>
</span>
</div>
</td>
<td class="site_table" style="width: 10%">
<?php if($scope->getReserved() == 1):?>
<img src="<?php echo \GocContextPath::getPath()?>img/tick.png" height="22px" style="vertical-align: middle;" />
<?php endif ?>
</td>
<?php if(!$params['portalIsReadOnly'] && $params['UserIsAdmin']):?>
<td class="site_table" style="width: 10%">
<script type="text/javascript" src="<?php echo \GocContextPath::getPath()?>javascript/confirm.js"></script>
Expand Down Expand Up @@ -189,4 +199,4 @@
});
})

</script>
</script>
13 changes: 10 additions & 3 deletions lib/Doctrine/deploy/AddScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@
foreach($scopes as $scope) {
$doctrineScope = new Scope();
$name = "";
$reserved = false;
foreach($scope as $key => $value) {
if($key == "name") {
$name = (string) $value;
}
switch ($key) {
case "name":
$name = (string) $value;
break;
case "reserved":
$reserved = ( $value == 1 );
break;
}
}
$doctrineScope->setName($name);
$doctrineScope->setReserved($reserved);
$entityManager->persist($doctrineScope);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/Doctrine/deploy/sampleData/Scopes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
<results>
<tag grid_id="0">
<name key="primary">Local</name>
<reserved>0</reserved>
</tag>
<tag grid_id="0">
<name key="primary">EGI</name>
<reserved>0</reserved>
</tag>
<tag grid_id="0">
<name key="primary">wlcg</name>
<reserved>1</reserved>
</tag>
</results>
21 changes: 20 additions & 1 deletion lib/Doctrine/entities/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Scope {

/** @Column(type="string", nullable=true) */
protected $description;

/** @Column(type="boolean", options={"default": false}) */
protected $reserved = false;

/**
* @return int The PK of this entity or null if not persisted
Expand All @@ -59,6 +62,14 @@ public function getName() {
public function getDescription() {
return $this->description;
}

/**
* Get the reserved status of this scope.
* @return boolean
*/
public function getReserved() {
return $this->reserved;
}

/**
* Set the unique name of this Scope instance.
Expand All @@ -75,7 +86,15 @@ public function setName($name) {
public function setDescription($description) {
$this->description = $description;
}


/**
* Set the reserved status of this scope.
* @param boolean $reserved
*/
public function setReserved($reserved) {
$this->reserved = $reserved;
}

/**
* Returns the unique name of this Scope instance.
* @return string
Expand Down
22 changes: 0 additions & 22 deletions lib/Gocdb_Services/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,28 +411,6 @@ public function getMinimumScopesRequired($entityType){
return intval($numScopesRequired);
}

/**
* Get an array of 'reserved' scope strings or an empty array if non are configured.
*
* <p>
* Reserved scopes can only be assiged by gocdb admin (and in future by selected roles);
* they can't be freely assigned to resources by their users/owners.
*
* @return array Reserved scopes as Strings
*/
public function getReservedScopeList() {
$reservedScopes = array ();
/* @var $reserved_scopes \SimpleXMLElement */
$reserved_scopes = $this->GetLocalInfoXML()->reserved_scopes;
if ($reserved_scopes != null) {
/* @var $scope \SimpleXMLElement */
foreach ( $reserved_scopes->children () as $scope ) {
$reservedScopes [] = ( string ) $scope;
}
}
return $reservedScopes;
}

public function getDefaultFilterByScope () {

if (strtolower($this->GetLocalInfoXML()->default_filter_by_scope) == 'true'){
Expand Down
Loading