Skip to content

Commit

Permalink
Add doc and proper readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Jul 5, 2019
1 parent 48103c5 commit cd95fe4
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 28 deletions.
10 changes: 10 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SS_BASE_URL="http://localhost"
SS_DATABASE_CLASS="MySQLDatabase"
SS_DATABASE_NAME="SS_admin"
SS_DATABASE_PASSWORD=""
SS_DATABASE_SERVER="localhost"
SS_DATABASE_USERNAME="root"

# SS_DEFAULT_ADMIN_USERNAME="admin"
# SS_DEFAULT_ADMIN_PASSWORD="admin"
# SS_ENVIRONMENT_TYPE="dev"
67 changes: 62 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,75 @@
# SilverStripe recipe-admin
`recipe-admin` is a SilverStripe recipe designed for projects that only need to use the "administration" part of SilverStripe to manage DataObjects:
`recipe-admin` is a SilverStripe recipe designed for "portal" projects that only need to use the "administration" part of SilverStripe to manage DataObjects:

## What does the recipe do?
* Strips out CMS functionality,
* Set the administration area as the default route,
* Add a generic login screen so you don't have style your own,
* Showcase generic DataObject that you can be copied and adapted for your purpose,
* Showcase how to set up default groups,
* Showcase a generic report.

## Installation
[View a short video of a recipe-admin project](https://youtu.be/J-H9SbvNQFo)


## Getting started

Add recipe-admin to your composer file.

```bash
# If starting a brand new project
composer create-project silverstripe/recipe-admin your-project-folder
composer create-project maxime-rainville/recipe-admin your-project-folder

# If you already have a composer file
composer require silverstripe/recipe-admin
```
composer require maxime-rainville/recipe-admin
```

Rename `.env-sample` to `.env` and adjust the settings according to your environment.

From here, just follow the normal set up steps for a SilverStripe project.

## What to do next?

The recipe comes with some simple examples to help you get started quickly. But you will need to tweak the example code to your use case.

### Set up your DataObjects

Two basic DataObjects are included in the basic recipe: Dog and Breed. Both of them come with sample code illustrating how to:
* define basic relations
* set basic validation rules
* define basic permissions.

Copy or rename these DataObject to suit your use case.

### Define an ModelAdmin controller

Dog and Breed can be managed via the "DogAdmin" `ModelAdmin`. Rename `DogAdmin` and adjust it to reference your own DataObjects.

### Set the default area in the Model

Recipe-admin is configured to have a default administration area. This will be the first screen your users will see after login into your portal.

By default this points to `DogAdmin`. Update `app/_config/routes.yml` to point to your own `ModelAdmin`

```diff
SilverStripe\Admin\AdminRootController:
url_base: 'a'
- default_panel: DogAdmin
+ default_panel: YourCustomAdmin
```

### Define some default data

`recipe-admin` comes with some default records. This pre-populates your project with some data with your first `dev/build`. When setting up a new environment, this allows you to quickly get started without having to load a database snapshot.

Adjust `app/_config/default-records.yml` to reflect your own DataObjects.

### Define some default groups

`recipe-admin` ships with a simple `DataExtension` showing you how do define default groups. Adjust the groups and permission define `app/_config/default-records.yml` to reflect your own DataObjects.

### Create some reports for your users

`BreedReport` shows you how you can create a custom report to allow your user to get refine view of their data.

If your users don't need this data, simply delete `BreedReport` and the "Report" panel will be hidden.
19 changes: 18 additions & 1 deletion app/_config/default-records.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,21 @@ Dog:
###############################################################################
SilverStripe\Security\Group:
extensions:
- DefaultGroupExtension
- DefaultGroupExtension
default_groups:
- Title: Dog Managers
Description: Can administer dogs
Permissions:
- DOG_EDIT
- DOG_VIEW
- BREED_VIEW
- CMS_ACCESS_DogAdmin
- Title: Breed Managers
Description: Can administer dogs and dog breeds
Permissions:
- BREED_EDIT
- BREED_VIEW
- DOG_EDIT
- DOG_VIEW
- CMS_ACCESS_DogAdmin
- CMS_ACCESS_ReportAdmin
2 changes: 1 addition & 1 deletion app/_config/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SilverStripe\Control\Director:
'': 'SilverStripe\Admin\AdminRootController'
'a': 'SilverStripe\Admin\AdminRootController'

# Set the default area in the MOdel
# Set the default panel in the administration area
SilverStripe\Admin\AdminRootController:
url_base: 'a'
default_panel: DogAdmin
3 changes: 3 additions & 0 deletions app/src/Admin/DogAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

use SilverStripe\Admin\ModelAdmin;

/**
* Simple ModelAdmin to manage dogs and breeds.
*/
class DogAdmin extends ModelAdmin {

private static $managed_models = [
Expand Down
23 changes: 4 additions & 19 deletions app/src/Extensions/DefaultGroupExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,13 @@
use SilverStripe\Security\Group;
use SilverStripe\Security\Permission;

/**
* Apply this extension to Group to add the ability to define default groups with pre-defined permissions.
*/
class DefaultGroupExtension extends DataExtension
{

private static $default_groups = [
[
'Title' => 'Dog Managers',
'Description' => 'Can administer dogs.',
'Permissions' => ['DOG_EDIT', 'DOG_VIEW', 'BREED_VIEW', 'CMS_ACCESS_DogAdmin']
],
[
'Title' => 'Breed Managers',
'Description' => 'Can administer dogs and dog breeds.',
'Permissions' => [
'BREED_EDIT',
'BREED_VIEW',
'DOG_EDIT',
'DOG_VIEW',
'CMS_ACCESS_DogAdmin',
'CMS_ACCESS_ReportAdmin'
]
]
];
private static $default_groups = [];

public function requireDefaultRecords()
{
Expand Down
3 changes: 3 additions & 0 deletions app/src/Reports/BreedReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use SilverStripe\ORM\DB;
use SilverStripe\Versioned\Versioned;

/**
* Simple report counting the number of dogs for each breed.
*/
class BreedReport extends Report
{

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "silverstripe/recipe-admin",
"name": "maxime-rainville/recipe-admin",
"description": "Starting point for a admin only SilverStripe project.",
"type": "silverstripe-recipe",
"require": {
Expand All @@ -8,7 +8,7 @@
"silverstripe/admin": "^1.4.1",
"silverstripe/reports": "^4.4.1",
"silverstripe/siteconfig": "^4.4.1",
"silverstripe/login-forms": "^1"
"silverstripe/login-forms": "^4.0.0-beta1"
},
"license": "BSD-3-Clause",
"authors": [
Expand Down

0 comments on commit cd95fe4

Please sign in to comment.