Skip to content

Commit

Permalink
Code cleanup and updated to take advantage of new Craft 2.5 plugin fe…
Browse files Browse the repository at this point in the history
…atures.
  • Loading branch information
angrybrad committed Dec 21, 2015
1 parent f4ab424 commit 7f2edc9
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 8 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,14 @@ To limit a user group’s access to an asset source, follow these steps:
Note that if a user belongs to multiple groups, and one of the groups has access to the entire asset source from the Asset Subfolder Access settings, then the restrictions won’t be applied.

Admins will always have access to the entire asset source, regardless of what user group(s) they may belong to.


## Changelog

### 1.1

- Updated to take advantage of new Craft 2.5 plugin features.

### 1.0

- Initial release
95 changes: 87 additions & 8 deletions assetsubfolderaccess/AssetSubfolderAccessPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,73 @@

class AssetSubfolderAccessPlugin extends BasePlugin
{
function getName()
/**
* @return mixed
*/
public function getName()
{
return Craft::t('Asset Subfolder Access');
}

function getVersion()
/**
* @return string
*/
public function getVersion()
{
return '1.0';
}

function getDeveloper()
/**
* @return string
*/
public function getSchemaVersion()
{
return '1.0.0';
}

/**
* @return string
*/
public function getDeveloper()
{
return 'Pixel & Tonic';
}

function getDeveloperUrl()
/**
* @return string
*/
public function getDeveloperUrl()
{
return 'http://pixelandtonic.com';
}

protected function defineSettings()
/**
* @return string
*/
public function getPluginUrl()
{
return array(
'accessibleFolders' => array(AttributeType::Mixed, 'default' => array()),
);
return 'https://github.com/pixelandtonic/AssetSubfolderAccess';
}

/**
* @return string
*/
public function getDocumentationUrl()
{
return $this->getPluginUrl().'/blob/master/README.md';
}

/**
* @return string
*/
public function getReleaseFeedUrl()
{
return 'https://raw.githubusercontent.com/pixelandtonic/AssetSubfolderAccess/master/releases.json';
}

/**
* @return string
*/
public function getSettingsHtml()
{
$html = '<p class="first">For each user group, choose which subfolders they should be allowed to access from the Assets index page.</p>';
Expand Down Expand Up @@ -102,6 +142,10 @@ public function getSettingsHtml()
return $html;
}

/**
* @param $sources
* @param $context
*/
public function modifyAssetSources(&$sources, $context)
{
// If the current user is an admin, just let them see everything
Expand Down Expand Up @@ -136,6 +180,21 @@ public function modifyAssetSources(&$sources, $context)
}
}

/**
* @return array
*/
protected function defineSettings()
{
return array(
'accessibleFolders' => array(AttributeType::Mixed, 'default' => array()),
);
}

/**
* @param $key
*
* @return bool|int
*/
private function _getFolderIdFromSourceKey($key)
{
if (strncmp($key, 'folder:', 7) === 0)
Expand All @@ -148,6 +207,12 @@ private function _getFolderIdFromSourceKey($key)
}
}

/**
* @param $parentFolderId
* @param $accessibleFolders
*
* @return bool
*/
private function _shouldOverrideSource($parentFolderId, $accessibleFolders)
{
$userGroups = craft()->userSession->getUser()->getGroups();
Expand All @@ -173,6 +238,13 @@ private function _shouldOverrideSource($parentFolderId, $accessibleFolders)
return true;
}

/**
* @param $parentSource
* @param $parentFolderId
* @param $accessibleFolders
*
* @return array
*/
private function _filterSubfolderSources($parentSource, $parentFolderId, $accessibleFolders)
{
if (!isset($parentSource['nested']))
Expand All @@ -195,6 +267,13 @@ private function _filterSubfolderSources($parentSource, $parentFolderId, $access
return $newSources;
}

/**
* @param $parentFolderId
* @param $subfolderId
* @param $accessibleFolders
*
* @return bool
*/
private function _canAccessSubfolder($parentFolderId, $subfolderId, $accessibleFolders)
{
$userGroups = craft()->userSession->getUser()->getGroups();
Expand Down
10 changes: 10 additions & 0 deletions releases.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"version": "1.1",
"downloadUrl": "https://github.com/pixelandtonic/AssetSubfolderAccess/archive/1.1.zip",
"date": "2015-20-20T12:00:00-08:00",
"notes": [
"[Improved] Updated to take advantage of new Craft 2.5 plugin features."
]
}
]

0 comments on commit 7f2edc9

Please sign in to comment.