2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* A security group.
|
2008-10-16 02:49:51 +02:00
|
|
|
*
|
2008-02-25 03:10:37 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage security
|
|
|
|
*/
|
2007-07-19 12:40:28 +02:00
|
|
|
class Group extends DataObject {
|
|
|
|
|
|
|
|
static $db = array(
|
|
|
|
"Title" => "Varchar",
|
|
|
|
"Description" => "Text",
|
|
|
|
"Code" => "Varchar",
|
|
|
|
"Locked" => "Boolean",
|
|
|
|
"Sort" => "Int",
|
2008-04-26 08:35:03 +02:00
|
|
|
"IPRestrictions" => "Text",
|
2009-08-10 06:32:39 +02:00
|
|
|
"HtmlEditorConfig" => "Varchar"
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
2008-10-16 02:49:51 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $has_one = array(
|
2008-11-21 02:06:21 +01:00
|
|
|
"Parent" => "Group",
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
2008-10-16 02:49:51 +02:00
|
|
|
|
2008-08-09 08:53:26 +02:00
|
|
|
static $has_many = array(
|
|
|
|
"Permissions" => "Permission",
|
2008-11-21 02:06:21 +01:00
|
|
|
"Groups" => "Group"
|
2008-08-09 08:53:26 +02:00
|
|
|
);
|
2008-10-16 02:49:51 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
static $many_many = array(
|
|
|
|
"Members" => "Member",
|
2009-10-16 00:27:56 +02:00
|
|
|
"Roles" => "PermissionRole",
|
2007-07-19 12:40:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
static $extensions = array(
|
|
|
|
"Hierarchy",
|
|
|
|
);
|
|
|
|
|
2010-01-12 23:49:39 +01:00
|
|
|
function getAllChildren() {
|
|
|
|
$doSet = new DataObjectSet();
|
|
|
|
|
2010-03-09 03:28:57 +01:00
|
|
|
if ($children = DataObject::get('Group', '"ParentID" = '.$this->ID)) {
|
2010-01-12 23:49:39 +01:00
|
|
|
foreach($children as $child) {
|
|
|
|
$doSet->push($child);
|
|
|
|
$doSet->merge($child->getAllChildren());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $doSet;
|
|
|
|
}
|
|
|
|
|
2008-04-09 13:34:10 +02:00
|
|
|
/**
|
|
|
|
* Caution: Only call on instances, not through a singleton.
|
|
|
|
*
|
|
|
|
* @return FieldSet
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = new FieldSet(
|
|
|
|
new TabSet("Root",
|
|
|
|
new Tab(_t('SecurityAdmin.MEMBERS', 'Members'),
|
2008-11-02 21:04:10 +01:00
|
|
|
new TextField("Title", $this->fieldLabel('Title')),
|
2008-04-09 13:34:10 +02:00
|
|
|
$memberList = new MemberTableField(
|
|
|
|
$this,
|
|
|
|
"Members",
|
2008-04-17 12:12:01 +02:00
|
|
|
$this,
|
2008-04-09 13:34:10 +02:00
|
|
|
null,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
),
|
|
|
|
|
2009-10-16 00:40:52 +02:00
|
|
|
$permissionsTab = new Tab(_t('SecurityAdmin.PERMISSIONS', 'Permissions'),
|
2009-10-29 00:03:35 +01:00
|
|
|
new PermissionCheckboxSetField(
|
|
|
|
'Permissions',
|
2010-03-10 03:22:44 +01:00
|
|
|
false,
|
2009-10-29 00:03:35 +01:00
|
|
|
'Permission',
|
2009-11-03 02:00:54 +01:00
|
|
|
'GroupID',
|
2010-02-23 01:54:13 +01:00
|
|
|
$this
|
|
|
|
)
|
2008-04-26 08:27:15 +02:00
|
|
|
),
|
2009-10-29 00:03:35 +01:00
|
|
|
|
2008-04-26 08:27:15 +02:00
|
|
|
new Tab(_t('Security.IPADDRESSES', 'IP Addresses'),
|
|
|
|
new LiteralField("", _t('SecurityAdmin.IPADDRESSESHELP',"<p>You can restrict this group to a particular
|
2008-07-28 09:27:40 +02:00
|
|
|
IP address range (one range per line). <br />Ranges can be in any of the following forms: <br />
|
2008-04-26 08:27:15 +02:00
|
|
|
203.96.152.12<br />
|
|
|
|
203.96.152/24<br />
|
|
|
|
203.96/16<br />
|
|
|
|
203/8<br /><br />If you enter one or more IP address ranges in this box, then members will only get
|
|
|
|
the rights of being in this group if they log on from one of the valid IP addresses. It won't prevent
|
|
|
|
people from logging in. This is because the same user might have to log in to access parts of the
|
|
|
|
system without IP address restrictions.")),
|
|
|
|
new TextareaField("IPRestrictions", "IP Ranges", 10)
|
2008-04-09 13:34:10 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2009-10-16 00:40:52 +02:00
|
|
|
|
2010-02-23 02:00:52 +01:00
|
|
|
// Only add a dropdown for HTML editor configurations if more than one is available.
|
|
|
|
// Otherwise Member->getHtmlEditorConfigForCMS() will default to the 'cms' configuration.
|
|
|
|
$editorConfigMap = HtmlEditorConfig::get_available_configs_map();
|
|
|
|
if(count($editorConfigMap) > 1) {
|
|
|
|
$fields->addFieldToTab('Root.Permissions',
|
|
|
|
new DropdownField(
|
|
|
|
'HtmlEditorConfig',
|
|
|
|
'HTML Editor Configuration',
|
|
|
|
$editorConfigMap
|
|
|
|
),
|
|
|
|
'Permissions'
|
|
|
|
);
|
|
|
|
}
|
2008-04-09 13:34:10 +02:00
|
|
|
|
2008-04-26 08:27:15 +02:00
|
|
|
if(!Permission::check('EDIT_PERMISSIONS')) {
|
|
|
|
$fields->removeFieldFromTab('Root', 'Permissions');
|
|
|
|
$fields->removeFieldFromTab('Root', 'IP Addresses');
|
|
|
|
}
|
2009-10-16 00:13:19 +02:00
|
|
|
|
2010-03-10 03:22:44 +01:00
|
|
|
// Only show the "Roles" tab if permissions are granted to edit them,
|
|
|
|
// and at least one role exists
|
2009-10-16 00:23:39 +02:00
|
|
|
if(Permission::check('APPLY_ROLES') && DataObject::get('PermissionRole')) {
|
|
|
|
$fields->addFieldToTab('Root.' . _t('SecurityAdmin.ROLES', 'Roles'),
|
|
|
|
new LiteralField(
|
|
|
|
"",
|
|
|
|
"<p>" .
|
|
|
|
_t('SecurityAdmin.ROLESDESCRIPTION',
|
|
|
|
"This section allows you to add roles to this group. Roles are logical groupings of permissions, which can be editied in the Roles tab"
|
|
|
|
) .
|
|
|
|
"</p>"
|
|
|
|
)
|
2009-10-15 23:53:15 +02:00
|
|
|
);
|
2009-10-16 00:40:52 +02:00
|
|
|
|
2010-02-23 02:00:35 +01:00
|
|
|
// Add roles (and disable all checkboxes for inherited roles)
|
|
|
|
$allRoles = Permission::check('ADMIN') ? DataObject::get('PermissionRole') : DataObject::get('PermissionRole', 'OnlyAdminCanApply = 0');
|
|
|
|
$groupRoles = $this->Roles();
|
|
|
|
$inheritedRoles = new DataObjectSet();
|
|
|
|
$ancestors = $this->getAncestors();
|
|
|
|
foreach($ancestors as $ancestor) {
|
|
|
|
$ancestorRoles = $ancestor->Roles();
|
|
|
|
if($ancestorRoles) $inheritedRoles->merge($ancestorRoles);
|
|
|
|
}
|
|
|
|
$fields->findOrMakeTab('Root.Roles', 'Root.' . _t('SecurityAdmin.ROLES', 'Roles'));
|
|
|
|
$fields->addFieldToTab(
|
|
|
|
'Root.Roles',
|
|
|
|
$rolesField = new CheckboxSetField('Roles', 'Roles', $allRoles)
|
|
|
|
);
|
|
|
|
$rolesField->setDefaultItems($inheritedRoles->column('ID'));
|
|
|
|
$rolesField->setDisabledItems($inheritedRoles->column('ID'));
|
2009-10-16 00:23:39 +02:00
|
|
|
}
|
2009-10-15 23:53:15 +02:00
|
|
|
|
2008-04-09 13:34:10 +02:00
|
|
|
$memberList->setController($this);
|
2010-02-23 01:26:17 +01:00
|
|
|
$memberList->setPermissions(array('show', 'edit', 'delete', 'export', 'add', 'inlineadd'));
|
2008-04-09 13:34:10 +02:00
|
|
|
$memberList->setParentClass('Group');
|
|
|
|
$memberList->setPopupCaption(_t('SecurityAdmin.VIEWUSER', 'View User'));
|
2010-02-23 01:53:57 +01:00
|
|
|
$memberList->setRelationAutoSetting(false);
|
2008-04-09 13:34:10 +02:00
|
|
|
|
|
|
|
$fields->push($idField = new HiddenField("ID"));
|
|
|
|
|
2008-08-14 01:57:53 +02:00
|
|
|
$this->extend('updateCMSFields', $fields);
|
|
|
|
|
2008-04-09 13:34:10 +02:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2009-04-29 02:07:39 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param boolean $includerelations a boolean value to indicate if the labels returned include relation fields
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function fieldLabels($includerelations = true) {
|
|
|
|
$labels = parent::fieldLabels($includerelations);
|
2008-11-02 21:04:10 +01:00
|
|
|
$labels['Title'] = _t('SecurityAdmin.GROUPNAME', 'Group name');
|
|
|
|
$labels['Description'] = _t('Group.Description', 'Description');
|
|
|
|
$labels['Code'] = _t('Group.Code', 'Group Code', PR_MEDIUM, 'Programmatical code identifying a group');
|
|
|
|
$labels['Locked'] = _t('Group.Locked', 'Locked?', PR_MEDIUM, 'Group is locked in the security administration area');
|
|
|
|
$labels['Sort'] = _t('Group.Sort', 'Sort Order');
|
|
|
|
$labels['IPRestrictions'] = _t('Group.IPRestrictions', 'IP Address Restrictions');
|
2009-04-29 02:07:39 +02:00
|
|
|
if($includerelations){
|
|
|
|
$labels['Parent'] = _t('Group.Parent', 'Parent Group', PR_MEDIUM, 'One group has one parent group');
|
|
|
|
$labels['Permissions'] = _t('Group.has_many_Permissions', 'Permissions', PR_MEDIUM, 'One group has many permissions');
|
|
|
|
$labels['Members'] = _t('Group.many_many_Members', 'Members', PR_MEDIUM, 'One group has many members');
|
|
|
|
}
|
2008-11-02 21:04:10 +01:00
|
|
|
|
|
|
|
return $labels;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-12-06 03:43:46 +01:00
|
|
|
* Add a member to a group. This will create the group if the given
|
|
|
|
* group code doesn't work.
|
2007-07-19 12:40:28 +02:00
|
|
|
*
|
|
|
|
* @param DataObject $member
|
|
|
|
* @param string $groupcode
|
|
|
|
*/
|
|
|
|
static function addToGroupByName($member, $groupcode) {
|
2008-11-24 10:31:14 +01:00
|
|
|
$group = DataObject::get_one('Group', "\"Code\" = '" . Convert::raw2sql($groupcode). "'");
|
2007-07-19 12:40:28 +02:00
|
|
|
if($group) {
|
|
|
|
$member->Groups()->add($group);
|
|
|
|
}
|
2009-12-06 03:43:46 +01:00
|
|
|
else {
|
|
|
|
$group = new Group();
|
|
|
|
$group->Code = $groupcode;
|
|
|
|
$group->Title = $groupcode;
|
|
|
|
$group->write();
|
|
|
|
|
|
|
|
$member->Groups()->add($group);
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overloaded getter.
|
2008-10-16 02:49:51 +02:00
|
|
|
*
|
|
|
|
* @TODO Where is this used, why is this overloaded?
|
2007-07-19 12:40:28 +02:00
|
|
|
*
|
|
|
|
* @param $limit string SQL
|
|
|
|
* @param $offset int
|
|
|
|
* @param $filter string SQL
|
|
|
|
* @param $sort string SQL
|
|
|
|
* @param $join string SQL
|
|
|
|
* @return ComponentSet
|
|
|
|
*/
|
|
|
|
public function Members($limit = "", $offset = "", $filter = "", $sort = "", $join = "") {
|
|
|
|
$table = "Group_Members";
|
|
|
|
if($filter) $filter = is_array($filter) ? $filter : array($filter);
|
|
|
|
|
|
|
|
if( is_numeric( $limit ) ) {
|
|
|
|
if( is_numeric( $offset ) )
|
2008-11-24 10:31:14 +01:00
|
|
|
$limit = "$limit OFFSET $offset";
|
2007-07-19 12:40:28 +02:00
|
|
|
else
|
2008-11-24 10:31:14 +01:00
|
|
|
$limit = "$limit OFFSET 0";
|
2007-07-19 12:40:28 +02:00
|
|
|
} else {
|
|
|
|
$limit = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all of groups that this group contains
|
|
|
|
$groupFamily = implode(", ", $this->collateFamilyIDs());
|
|
|
|
|
2008-11-24 00:28:16 +01:00
|
|
|
$filter[] = "\"$table\".\"GroupID\" IN ($groupFamily)";
|
|
|
|
$join .= " INNER JOIN \"$table\" ON \"$table\".\"MemberID\" = \"Member\".\"ID\"" . Convert::raw2sql($join);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
$result = singleton("Member")->instance_get(
|
|
|
|
$filter,
|
|
|
|
$sort,
|
|
|
|
$join,
|
|
|
|
$limit,
|
|
|
|
"ComponentSet" // datatype
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!$result) $result = new ComponentSet();
|
|
|
|
|
|
|
|
$result->setComponentInfo("many-to-many", $this, "Group", $table, "Member");
|
|
|
|
foreach($result as $item) $item->GroupID = $this->ID;
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function map($filter = "", $sort = "", $blank="") {
|
|
|
|
$ret = new SQLMap(singleton('Group')->extendedSQL($filter, $sort));
|
|
|
|
if($blank){
|
|
|
|
$blankGroup = new Group();
|
|
|
|
$blankGroup->Title = $blank;
|
|
|
|
$blankGroup->ID = 0;
|
|
|
|
|
|
|
|
$ret->getItems()->shift($blankGroup);
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a set of this record's "family" of IDs - the IDs of
|
2008-11-03 02:55:59 +01:00
|
|
|
* this record and all its descendants.
|
|
|
|
* @return array
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
public function collateFamilyIDs() {
|
2008-11-03 02:55:59 +01:00
|
|
|
$familyIDs = array();
|
2007-07-19 12:40:28 +02:00
|
|
|
$chunkToAdd = array(array("ID" => $this->ID));
|
|
|
|
|
|
|
|
while($chunkToAdd) {
|
2009-11-16 06:02:19 +01:00
|
|
|
$idList = array();
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($chunkToAdd as $item) {
|
2008-11-03 02:55:59 +01:00
|
|
|
$idList[] = $item['ID'];
|
|
|
|
$familyIDs[] = $item['ID'];
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-11-16 06:02:19 +01:00
|
|
|
$idList = implode(',', $idList);
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// Get the children of *all* the groups identified in the previous chunk.
|
|
|
|
// This minimises the number of SQL queries necessary
|
2008-11-24 00:28:16 +01:00
|
|
|
$sql = $this->extendedSQL("\"ParentID\" IN ($idList)", "");
|
2009-11-16 06:02:19 +01:00
|
|
|
$dbResult = $sql->execute();
|
|
|
|
$chunkToAdd = array();
|
|
|
|
foreach($dbResult as $item) $chunkToAdd[] = $item;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2008-11-03 02:55:59 +01:00
|
|
|
return $familyIDs;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of the IDs of this group and all its parents
|
|
|
|
*/
|
|
|
|
public function collateAncestorIDs() {
|
|
|
|
$parent = $this;
|
|
|
|
while(isset($parent)) {
|
|
|
|
$items[] = $parent->ID;
|
|
|
|
$parent = $parent->Parent;
|
|
|
|
}
|
|
|
|
return $items;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This isn't a decendant of SiteTree, but needs this in case
|
|
|
|
* the group is "reorganised";
|
|
|
|
*/
|
|
|
|
function cmsCleanup_parentChanged() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Override this so groups are ordered in the CMS
|
|
|
|
*/
|
|
|
|
public function stageChildren() {
|
2008-11-24 10:31:14 +01:00
|
|
|
return DataObject::get('Group', "\"Group\".\"ParentID\" = " . (int)$this->ID . " AND \"Group\".\"ID\" != " . (int)$this->ID, '"Sort"');
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function TreeTitle() {
|
2010-01-13 00:43:47 +01:00
|
|
|
if($this->hasMethod('alternateTreeTitle')) return $this->alternateTreeTitle();
|
|
|
|
else return htmlspecialchars($this->Title, ENT_QUOTES);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
2010-02-24 04:07:19 +01:00
|
|
|
function CMSTreeClasses($controller) {
|
|
|
|
$classes = $this->class;
|
|
|
|
|
|
|
|
if(!$this->canEdit()) $classes .= " disabled";
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Overloaded to ensure the code is always descent.
|
|
|
|
*/
|
|
|
|
public function setCode($val){
|
|
|
|
$this->setField("Code",SiteTree::generateURLSegment($val));
|
|
|
|
}
|
2007-10-30 04:17:18 +01:00
|
|
|
|
|
|
|
function onBeforeWrite() {
|
|
|
|
parent::onBeforeWrite();
|
|
|
|
|
2010-03-02 23:07:34 +01:00
|
|
|
if(stripos($this->Code, _t('SecurityAdmin.NEWGROUPPREFIX','new-')) === 0) {
|
2007-10-30 04:17:18 +01:00
|
|
|
$this->setCode($this->Title);
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
2009-12-10 04:44:35 +01:00
|
|
|
function onAfterDelete() {
|
|
|
|
parent::onAfterDelete();
|
|
|
|
|
|
|
|
// Delete associated permissions
|
|
|
|
$permissions = $this->Permissions();
|
|
|
|
foreach ( $permissions as $permission ) {
|
|
|
|
$permission->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-03 23:44:11 +01:00
|
|
|
/**
|
|
|
|
* Checks for permission-code CMS_ACCESS_SecurityAdmin.
|
|
|
|
* If the group has ADMIN permissions, it requires the user to have ADMIN permissions as well.
|
|
|
|
*
|
|
|
|
* @param $member Member
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canEdit($member = null) {
|
|
|
|
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) $member = Member::currentUser();
|
|
|
|
|
2009-02-04 00:33:28 +01:00
|
|
|
// decorated access checks
|
|
|
|
$results = $this->extend('canEdit', $member);
|
|
|
|
if($results && is_array($results)) if(!min($results)) return false;
|
|
|
|
|
|
|
|
if(
|
|
|
|
// either we have an ADMIN
|
|
|
|
(bool)Permission::checkMember($member, "ADMIN")
|
|
|
|
|| (
|
|
|
|
// or a privileged CMS user and a group without ADMIN permissions.
|
|
|
|
// without this check, a user would be able to add himself to an administrators group
|
|
|
|
// with just access to the "Security" admin interface
|
|
|
|
Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin") &&
|
|
|
|
!DataObject::get("Permission", "GroupID = $this->ID AND Code = 'ADMIN'")
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return true;
|
2008-04-26 08:35:39 +02:00
|
|
|
}
|
2009-02-04 00:33:28 +01:00
|
|
|
|
|
|
|
return false;
|
2008-02-25 03:10:37 +01:00
|
|
|
}
|
2009-02-02 00:49:53 +01:00
|
|
|
|
2009-02-03 23:44:11 +01:00
|
|
|
/**
|
|
|
|
* Checks for permission-code CMS_ACCESS_SecurityAdmin.
|
|
|
|
*
|
|
|
|
* @param $member Member
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function canView($member = null) {
|
|
|
|
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) $member = Member::currentUser();
|
|
|
|
|
2009-02-04 00:33:28 +01:00
|
|
|
// decorated access checks
|
|
|
|
$results = $this->extend('canView', $member);
|
|
|
|
if($results && is_array($results)) if(!min($results)) return false;
|
|
|
|
|
|
|
|
// user needs access to CMS_ACCESS_SecurityAdmin
|
|
|
|
if(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin")) return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function canDelete($member = null) {
|
|
|
|
if(!$member || !(is_a($member, 'Member')) || is_numeric($member)) $member = Member::currentUser();
|
|
|
|
|
|
|
|
// decorated access checks
|
|
|
|
$results = $this->extend('canDelete', $member);
|
|
|
|
if($results && is_array($results)) if(!min($results)) return false;
|
|
|
|
|
|
|
|
return $this->canEdit($member);
|
2009-02-02 00:49:53 +01:00
|
|
|
}
|
2008-02-25 03:10:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns all of the children for the CMS Tree.
|
|
|
|
* Filters to only those groups that the current user can edit
|
|
|
|
*/
|
|
|
|
function AllChildrenIncludingDeleted() {
|
2010-03-04 05:15:42 +01:00
|
|
|
$extInstance = $this->getExtensionInstance('Hierarchy');
|
2009-06-04 08:48:44 +02:00
|
|
|
$extInstance->setOwner($this);
|
|
|
|
$children = $extInstance->AllChildrenIncludingDeleted();
|
|
|
|
$extInstance->clearOwner();
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
$filteredChildren = new DataObjectSet();
|
|
|
|
|
|
|
|
if($children) foreach($children as $child) {
|
2009-02-03 23:44:11 +01:00
|
|
|
if($child->canView()) $filteredChildren->push($child);
|
2008-02-25 03:10:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $filteredChildren;
|
|
|
|
}
|
2008-04-26 08:35:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given IP address is granted access to this group.
|
|
|
|
* For unrestricted groups, this always returns true.
|
|
|
|
*/
|
|
|
|
function allowedIPAddress($ip) {
|
|
|
|
if(!$this->IPRestrictions) return true;
|
2008-08-13 03:42:56 +02:00
|
|
|
if(!$ip) return false;
|
|
|
|
|
2008-04-26 08:35:03 +02:00
|
|
|
$ipPatterns = explode("\n", $this->IPRestrictions);
|
|
|
|
foreach($ipPatterns as $ipPattern) {
|
|
|
|
$ipPattern = trim($ipPattern);
|
|
|
|
if(preg_match('/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/', $ipPattern, $matches)) {
|
|
|
|
if($ip == $ipPattern) return true;
|
|
|
|
} else if(preg_match('/^([0-9]+\.[0-9]+\.[0-9]+)\/24$/', $ipPattern, $matches)
|
|
|
|
|| preg_match('/^([0-9]+\.[0-9]+)\/16$/', $ipPattern, $matches)
|
|
|
|
|| preg_match('/^([0-9]+)\/8$/', $ipPattern, $matches)) {
|
|
|
|
if(substr($ip, 0, strlen($matches[1])) == $matches[1]) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-10 06:11:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add default records to database.
|
|
|
|
*
|
|
|
|
* This function is called whenever the database is built, after the
|
|
|
|
* database tables have all been created.
|
|
|
|
*/
|
|
|
|
public function requireDefaultRecords() {
|
|
|
|
parent::requireDefaultRecords();
|
|
|
|
|
|
|
|
// Add default author group if no other group exists
|
|
|
|
$allGroups = DataObject::get('Group');
|
|
|
|
if(!$allGroups) {
|
|
|
|
$authorGroup = new Group();
|
|
|
|
$authorGroup->Code = 'content-authors';
|
|
|
|
$authorGroup->Title = _t('Group.DefaultGroupTitleContentAuthors', 'Content Authors');
|
|
|
|
$authorGroup->Sort = 1;
|
|
|
|
$authorGroup->write();
|
|
|
|
Permission::grant($authorGroup->ID, 'CMS_ACCESS_CMSMain');
|
|
|
|
Permission::grant($authorGroup->ID, 'CMS_ACCESS_AssetAdmin');
|
|
|
|
Permission::grant($authorGroup->ID, 'CMS_ACCESS_CommentAdmin');
|
|
|
|
Permission::grant($authorGroup->ID, 'CMS_ACCESS_ReportAdmin');
|
|
|
|
Permission::grant($authorGroup->ID, 'SITETREE_REORGANISE');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add default admin group if none with permission code ADMIN exists
|
|
|
|
$adminGroups = Permission::get_groups_by_permission('ADMIN');
|
|
|
|
if(!$adminGroups) {
|
|
|
|
$adminGroup = new Group();
|
|
|
|
$adminGroup->Code = 'administrators';
|
|
|
|
$adminGroup->Title = _t('Group.DefaultGroupTitleAdministrators', 'Administrators');
|
|
|
|
$adminGroup->Sort = 0;
|
|
|
|
$adminGroup->write();
|
|
|
|
Permission::grant($adminGroup->ID, 'ADMIN');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Members are populated through Member->requireDefaultRecords()
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-06-22 04:42:42 +02:00
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
?>
|