Code Monkey home page Code Monkey logo

kirby-bouncer's Introduction

Kirby – Bouncer

Restrict access of a user role to a specific page (and its children) in the panel.

bouncer-screenshot


Overview

This plugin is completely free and published under the MIT license. However, if you are using it in a commercial project and want to help me keep up with maintenance, please consider making a donation of your choice or purchasing your license(s) through my affiliate link.


1. Installation

Download and copy this repository to /site/plugins/bouncer

Alternatively, you can install it with composer: composer require sylvainjule/bouncer


2. Setup

The intent of this plugin is to limit a user's ability to edit only their Account page + a page (and its children) selected in a Pages field.

  • First, create a new user role (for example, /site/blueprints/users/test.yml)
  • Set their permissions, and add a pages field:
title: Test

permissions:
  access:
    panel: true
    site: true
    settings: false
    languages: false
    users: false
  # ...
  user:
    changeRole: false
    delete: false
    update: false # else a user will be able to edit the page they have access to on their profile

fields:
  canaccess:
    label: 'The user will only be able to access:'
    type: pages
    multiple: false
    options: query
    query: site.pages # or any query that suits your needs
  • In your site/config/config.php, tell the plugin which role => fieldname associations to use:
return [
    'sylvainjule.bouncer.list' => [
        'test' => [ // match the filename without extension of the user blueprint
            'fieldname' => 'canaccess' 
        ]
    ]
];

2.1 Optional page switcher

(beta)

Since 1.0.1 a given user can access different pages. You can remove the multiple: false option from the blueprint:

# User role blueprint
title: Test

fields:
  canaccess:
    label: 'The user will only be able to access:'
    type: pages
    options: query
    query: site.pages # or any query that suits your needs

Add a bouncernav section in every page you'd like to display the page switcher on:

// Anywhere in any blueprint

(...)
sections:
  bouncernav:
    type: bouncernav

Then state in your config.php that you want to display the page switcher for a given user role:

return [
    'sylvainjule.bouncer.list' => [
        'test' => [
            'fieldname' => 'canaccess',
            'nav' => true
        ]
    ]
];

3. Disclaimer

I needed this functionnality for a website and turned it into a plugin. I hope it can prove helpful, but do not intend to extend it or support more refined restriction scenarios with this plugin.


4. License

MIT

kirby-bouncer's People

Contributors

bnomei avatar dependabot[bot] avatar hlp-pls avatar kerli81 avatar sylvainjule avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kirby-bouncer's Issues

Infinit reload on kirby installation caused by kirby-bouncer

When this plugin is installed and there is no account created, the panel login page reload for ever.

When I remove kirby-bouncer plugin, i can install kirby and create the first account.

Error message in the console
Object { status: "error", message: "Unauthenticated", code: 403, exception: "Kirby\\Exception\\PermissionException", key: "error.permission", file: "authentication.php", line: 23, details: [], route: "current-user" }

add comment to config snippet

i copied the snippet but decided to change the blueprint name and forgot about the config value since everything else seemed to work. a small comment (not just the information in the sentence above the snippet) could help spot this mistake later on.

return [
    'sylvainjule.bouncer.list' => [
        'test' => [ // match the filename without extension of the user blueprint
            'fieldname' => 'canaccess'
        ]
    ]
];

Selected pages are not showing up

My setup:

  • content

    • 1_class1
      • 1_student-a
        • student.txt
      • 2_student-b
        • student.txt
  • site

    • blueprints
      • users
        • student.yml

This is the student.yml file:

title: Student

permissions:
  access:
    panel: true
    site: true
    settings: false
    languages: false
    users: false
  # ...
  user:
    changeRole: false
    delete: false
    update: false # else a user will be able to edit the page they have access to on their profile

fields:
  canaccess:
    label: "The user will only be able to access:"
    type: pages
    options: query
    query: site.pages

Unfortunately it shows No pages selected yet in the pages view. I tried multiple query methods, but it never worked for me.
How can I add pages to the query?

"Basculer vers"

hello and thank you for the plugin. i am upgrading a project to kirby 4.2 installation and the newest realease of the plugin. somehow now it is hard coded in the JS 'Basculer vers'. in the previous version it said "Switch:". can you pelase look into this?

Better fields list declaration

Hello,
first of all, thank you for this plugin!

I think that the way as the field are declared may can be improved.

An example can be:

'sylvainjule.bouncer.list' => [
    'author' => [
        'fieldname' => 'access',
        'nav' => true
    ],
    'blog-editor' => [
        'fieldname' => 'access',
        'nav' => true
    ],
    'contributor' => [
        'fieldname' => 'access',
        'nav' => true
    ],
    'moderator' => [
        'fieldname' => 'access',
        'nav' => true
    ],
    'examplerole' => [
        'fieldname' => 'onlyAccess',
    ],
],

A more reusable way can be by adding the fields as keys and the roles inside as array|string.

Something like this:

'sylvainjule.bouncer.list' => [
    'access' => [
        'roles' => ['author', 'blog-editor', 'contributor', 'moderator'],
        'nav' => true
    ],
    'onlyAccess' => [
        'roles' => 'exampleRole',
    ],
]

Is only a suggestion 🙂

EDIT: The disadvantage is when you want the same field name with different options as the nav value.

Incompatible with 3.6.0

Hi Sylvain,

As you can see from he alpha version of 3.6.0 (https://getkirby.com/releases/3.6), we will remove vue-router with this release. Which of course means that your plugin's functionality would be rendered broken.

However, in anticipation we added two hooks

I would believe that with the panel.route:before hook, we could recreate your plugin. Likely even much simpler than the current setup. Let me know your thoughts - happy to collaborate.

Questions about Bouncer plugin and Permissions

Hello,

We’re attempting to use the Bouncer plugin because we'd like users to only have access to certain content pages, but we also want some of them to be able to edit users.

Is that possible with this plugin?

screenshot of bouncer settings from site/blueprints/users/staff.yml
Screenshot 2023-11-21 at 11 16 17 AM

Bouncer and Draft Status

I've set up bouncer and all is good (thanks) except users with their access controlled by bouncer can not nav to pages that they been given access to if those pages are draft. Is this expected? And if so is there a way around it?

Feature request: limit search results

Thanks for this very helpful plugin. Maybe this would be an interesting addition for your own needs too.

At the moment the panel seach function is showing all matching results, even in pages that are not visible to the current user. Of course they still can’t be accessed, but it would be nicer of they would not be visible in the first place. Not sure how hard this is to achieve.

Problems accessing subpages and options

Hi, and thank you for a great plugin!

I’m having some problems accessing subpages after updating to 1.0.4. There are also problems with the options; for example, I get “The dropdown is empty” when trying to click on “...” in cards or access the settings menu.

I verified the error with a clean install of the starter kit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.