# Cakedc/auth: owner permission not working

**URL:** https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319
**Category:** Plugins
**Created:** [May 18, 2018, 8:30am UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319 "2018-05-18T08:30:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)
#### Post date: [May 18, 2018, 8:30am UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/1 "2018-05-18T08:30:29Z")

</div>

Hello

Everything is working fine, I can change the permissions. Only the owner rule is not working.

The permissions :

```
return [
    'Users.SimpleRbac.permissions' => [
        //admin role allowed to all the things
        [
            'role' => 'admin',
            'prefix' => '*',
            'extension' => '*',
            'plugin' => '*',
            'controller' => '*',
            'action' => '*',
        ],
        //specific actions allowed for the all roles in Users plugin
        [
            'role' => '*',
            'plugin' => 'CakeDC/Users',
            'controller' => 'Users',
            'action' => ['profile', 'logout', 'linkSocial', 'callbackLinkSocial'],
        ],
        //all roles allowed to Pages/display
        [
            'role' => '*',
            //'plugin' => null,
            'controller' => 'Pages',
            'action' => 'display',
        ],
 
  [
        'role' => 'user',
        'controller' => 'Users',
        'action' => ['view'],
    ],
   [
        'role' => 'user',
        'controller' => 'Articles',
        'action' => ['index','add'],
    ],
     [
        'role' => 'user',
        'controller' => 'Articles',
        'action' => ['edit', 'delete'],
        'allowed' => new \CakeDC\Auth\Rbac\Rules\Owner([
            'ownerForeignKey' => 'user_id',
                            ]) //will pick by default the post id from the first pass param
    
        ],
]

```

];

Is there something I do wrong?

---

<div class="post-metadata">

### Author: ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.cakephp.org/u/hakim)
#### Post date: [May 21, 2018, 4:45pm UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/2 "2018-05-21T16:45:29Z")

</div>

This is a guess, but maybe the table name? eg …

```auto
 'allowed' => new Owner([
        'table' => 'UsersLocations',
        'id' => 'location_id',
                'ownerForeignKey' => 'user_id'
        ]),
```

---

<div class="post-metadata">

### Author: ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)
#### Post date: [May 24, 2018, 7:18pm UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/3 "2018-05-24T19:18:16Z")

</div>

@hakim: thank you for the respons.  
Unfortunately nothing is working. If I don’t get a solution or find a good tutorial I have to look for another plugin.

---

<div class="post-metadata">

### Author: ![hakim](https://avatars.discourse-cdn.com/v4/letter/h/97f17d/32.png) [@hakim](https://discourse.cakephp.org/u/hakim)
#### Post date: [May 25, 2018, 9:11am UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/4 "2018-05-25T09:11:24Z")

</div>

I came across similar issues. I removed the plugin and started from the beginning again, following the documentation and it worked (during development I must have messed up the config somewhere).

Ok, I know you might have checked this already, but does Articles have a relation (belongsTo) with Users, does it have a user\_id column in the Articles table?

---

<div class="post-metadata">

### Author: ![steinkel](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/steinkel/32/56_2.png) [@steinkel](https://discourse.cakephp.org/u/steinkel)
#### Post date: [May 25, 2018, 3:59pm UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/5 "2018-05-25T15:59:11Z")

</div>

@jmebis please post your associations for the ArticlesTable, also your database schema. Check the query generated (in debugKit) to check the Owner permissions by the plugin, and also ensure the logged in user has role=user.

The `'ownerForeignKey' => 'user_id',` is the default configuration, you can remove it.

As suggested, you are missing the table configuration if the reference table is not Articles, example

`'table' => 'SomeOtherTable',`

With the default configuration, the Owner rule will check

- The Articles table has a user\_id column
- The value of user\_id matches with the logged in user
- The article you are checking is passed as a param to the action, for example, `/articles/edit/7`
  - In this case the rule will get the article id=7 `user_id` matches the logged in user id

Here’s some more detail about config used for the Owner rule: [https://github.com/CakeDC/auth/blob/master/src/Rbac/Rules/Owner.php#L27](https://github.com/CakeDC/auth/blob/master/src/Rbac/Rules/Owner.php#L27)

---

<div class="post-metadata">

### Author: ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)
#### Post date: [May 31, 2018, 6:59pm UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/6 "2018-05-31T18:59:17Z")

</div>

> The article you are checking is passed as a param to the action, for example, /articles/edit/7

I followed the tutorial on [book.cakephp.org](http://book.cakephp.org) and they are using slug.  
So the edit url is like this: /articles/edit/slug

I’m no trying to avoid using a slug.

---

<div class="post-metadata">

### Author: ![jmebis](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jmebis](https://discourse.cakephp.org/u/jmebis)
#### Post date: [May 31, 2018, 8:32pm UTC](https://discourse.cakephp.org/t/cakedc-auth-owner-permission-not-working/4319/7 "2018-05-31T20:32:18Z")

</div>

Jep, that was the stupid but annoying problem.

Thank you for your time!
