Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Densham committed Oct 29, 2015
2 parents aeba17e + 3bfe838 commit c5f712e
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/framework export-ignore
/cms export-ignore
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build
composer.lock
docs
framework
cms
vendor
33 changes: 33 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
filter:
excluded_paths: [tests/*]
checks:
php:
code_rating: true
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true
tools:
external_code_coverage: false
php_analyzer: true
php_code_coverage: false
php_code_sniffer:
config:
standard: PSR2
filter:
paths: ['src']
php_loc:
enabled: true
excluded_dirs: [_config, assets, lang, templates, framework, cms, vendor, tests]
php_cpd:
enabled: true
excluded_dirs: [_config, assets, lang, templates, framework, cms, vendor, tests]
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All Notable changes to `studiobonito/silverstripe-security` will be documented in this file

## [Unreleased]

[Unreleased]: https://github.com/studiobonito/silverstripe-security/compare/1.0.0...HEAD
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/studiobonito/silverstripe-security/tree/develop).


## Pull Requests

- **Development branch** - You're pull request should be made against the `develop` branch.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **Create feature branches** - Don't ask us to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please squash them before submitting.


## Running Tests

``` bash
$ phpunit
```


**Happy coding**!
27 changes: 27 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (c) 2015, Studio Bonito Ltd.

All rights reserved.

> Redistribution and use in source and binary forms, with or without modification, are
> permitted provided that the following conditions are met:
>
> 1. Redistributions of source code must retain the above copyright notice, this list of
> conditions and the following disclaimer.
>
> 2. Redistributions in binary form must reproduce the above copyright notice, this list
> of conditions and the following disclaimer in the documentation and/or other materials
> provided with the distribution.
>
> THIS SOFTWARE IS PROVIDED BY STUDIO BONITO LTD "AS IS" AND ANY EXPRESS OR IMPLIED
> WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
> FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STUDIO BONITO LTD OR
> CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
> ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
>
> The views and conclusions contained in the software and documentation are those of the
> authors and should not be interpreted as representing official policies, either expressed
> or implied, of Studio Bonito Ltd.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Security Module

[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]

## Overview

Provide ModelAdmin replacement for SecurityAdmin in SilverStripe CMS.

![Screenshot of Security Module](./assets/images/screenshot.png)

## Requirements

- SilverStripe 3.1.15 or newer.

## Install

### Via Composer

``` bash
$ composer require studiobonito/silverstripe-security
```

### Manually

Copy the 'silverstripe-security' folder to the root of your SilverStripe installation.

## Usage

The model provides a drop in replacement for the default 'Security' tab in the SilverStripe CMS.
Installing the module will replace the default 'Security' tab and replace it with this one.
This 'Security' tab is based on `ModelAdmin` and provides simple filtering which is good for managing sites with large numbers of users/groups.

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Tom Densham][link-author]
- [All Contributors][link-contributors]

## License

The BSD-2-Clause License. Please see [License File](LICENSE.md) for more information.

[ico-version]: https://img.shields.io/github/release/studiobonito/silverstripe-security.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-BSD-brightgreen.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/studiobonito/silverstripe-security.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/studiobonito/silverstripe-security.svg?style=flat-square

[link-packagist]: https://packagist.org/packages/studiobonito/silverstripe-security
[link-code-quality]: https://scrutinizer-ci.com/g/studiobonito/silverstripe-security
[link-downloads]: https://packagist.org/packages/studiobonito/silverstripe-security
[link-author]: https://github.com/nedmas
[link-contributors]: ../../contributors
9 changes: 9 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Name: security
---
LeftAndMain:
extensions:
- StudioBonito\Security\Extensions\DisableSecurityAdminExtension
Group:
extensions:
- StudioBonito\Security\Extensions\GroupMembersFieldExtension
Binary file added assets/images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "studiobonito/silverstripe-security",
"description": "Provide ModelAdmin replacement for SecurityAdmin in SilverStripe CMS.",
"type": "silverstripe-module",
"keywords": [
"studiobonito",
"silverstripe-security",
"silverstripe",
"security",
"member"
],
"homepage": "https://github.com/studiobonito/silverstripe-security",
"license": "BSD-2-Clause",
"authors": [
{
"name": "Tom Densham",
"email": "[email protected]",
"homepage": "http://www.studiobonito.co.uk",
"role": "Developer"
}
],
"require": {
"php": ">=5.3.0",
"silverstripe/framework": "~3.1.15",
"silverstripe/cms": "~3.1.15"
},
"require-dev": {
"scrutinizer/ocular": "~1.1"
},
"suggest": {
"unclecheese/betterbuttons": "Improves the usability of ModelAdmin based interfaces.",
"silverstripe-australia/gridfieldextensions": "Allows better Member lookup when editing a Group."
},
"autoload": {
"psr-4": {
"StudioBonito\\SilverStripe\\Security\\": "src"
}
}
}
122 changes: 122 additions & 0 deletions src/Controllers/MemberAdmin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?php namespace StudioBonito\Security\Controllers;

use GridFieldButtonRow;
use GridFieldExportButton;
use GridFieldPrintButton;

/**
* ModelAdmin implementation for handling member, group and role data-objects.
*
* @author Tom Densham <[email protected]>
* @copyright Studio Bonito Ltd.
*/
class MemberAdmin extends \ModelAdmin
{
/**
* The current url segment. {@link LeftAndMain::$url_segment}
*
* @config
* @var string
*/
private static $url_segment = 'members';

/**
* The current menu title. {@link LeftAndMain::$menu_title}
*
* @config
* @var string
*/
private static $menu_title = 'Security';

/**
* The menu icon.
*
* @config
* @var string
*/
private static $menu_icon = 'framework/admin/images/menu-icons/16x16/community.png';

/**
* @config
* @var int
*/
private static $menu_priority = -1;

/**
* List of all managed {@link DataObject}s in this interface. {@link ModelAdmin::$managed_models}
*
* @config
* @var array|string
*/
private static $managed_models = array(
'Member',
'Group',
'PermissionRole',
);

/**
* List of all {@link DataObject}s which can be imported through a subclass of {@link BulkLoader} (mostly CSV data).
*
* @config
* @var array
*/
private static $model_importers = array(
'Member' => 'MemberCsvBulkLoader',
'Group' => 'GroupCsvBulkLoader',
);

/**
* Override managed model labels with CMS defaults for member, group and role.
*
* @return array
*/
public function getManagedModels()
{
$models = parent::getManagedModels();

if (isset($models['Member']) && isset($models['Member']['title'])) {
$models['Member']['title'] = _t('SecurityAdmin.Users', 'Users');
}

if (isset($models['Group']) && isset($models['Group']['title'])) {
$models['Group']['title'] = singleton('Group')->i18n_plural_name();
}

if (isset($models['PermissionRole']) && isset($models['PermissionRole']['title'])) {
$models['PermissionRole']['title'] = _t('SecurityAdmin.TABROLES', 'Roles');
}

return $models;
}

/**
* Override gridfield configuration to provide a consistent UX.
*
* @param null $id
* @param null $fields
*
* @return \CMSForm
*/
public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm($id, $fields);

$gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
$gridFieldConfig = $gridField->getConfig();

$gridFieldConfig->addComponent(new GridFieldButtonRow('after'));

$gridFieldConfig->removeComponentsByType('GridFieldExportButton');

$exportButton = new GridFieldExportButton('buttons-after-left');
$exportButton->setExportColumns($this->getExportFields());

$gridFieldConfig->addComponent($exportButton);

$gridFieldConfig->removeComponentsByType('GridFieldPrintButton');

$gridFieldConfig->addComponent(new GridFieldPrintButton('buttons-after-left'));

return $form;
}
}
20 changes: 20 additions & 0 deletions src/Extensions/DisableSecurityAdminExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php namespace StudioBonito\Security\Extensions;

use CMSMenu;

/**
* Simple extension to remove default security admin class from menu.
*
* @author Tom Densham <[email protected]>
* @copyright Studio Bonito Ltd.
*/
class DisableSecurityAdminExtension extends \Extension
{
/**
* Disable SecurityAdmin menu item.
*/
public function init()
{
CMSMenu::remove_menu_item('SecurityAdmin');
}
}
Loading

0 comments on commit c5f712e

Please sign in to comment.