Kirby 2.4.0 beta 2: I cannot find Docs for the site files at site options

What are the permissions, I need to control the permission to add, delete, update etc. the “site files” on the site options page (files located directly in the directory /content/)?

Edit: This is handled via the panel.file.upload option!

But as Kirby 2.4.0 itself, the docs are still in beta mode as well and we’ll try to update them asap.

1 Like

In the Docs I read

You can block site option updates. This will switch all form fields to readonly fields and hide the save button.

But I want to control the “site files” different from the right part of this panel page.

Thank you for your work. I know that this is very time-consuming.:slight_smile::slight_smile:

Can you or @lukasbestle give me a smal tip here, how I can do this. Or needs it some new code?

Just tested this and does not seem to be a panel.site.upload option. But since you permissions are very flexible, you should be able to code that yourself.

1 Like

If I need realy PHP code to do this, I ask the Kirby team to add that code in the final Kirby version 2.4.0.

Sorry, I’m no PHP coder. Therefore I like Kirby very much.

It’s not really difficult, you can do all that using the panel.file.upload function, here is an example of something really fine tuned:

'panel.file.upload' => function($file) {
    
  if(
    $file->page()->template() === 'article' && 
    $this->user()->username() === 'sonja' && 
    $file->mime() === 'image/jpeg' && 
    $file->width() < 1024 && 
    $file->height() < 1024 && 
    $file->exif()->camera()->make() === 'Canon'
  ) {
    return true;
  } else {
    return false;
  }

}
1 Like

Sorry, I’m stupid, but I cannot see, that your code only effects the “site files” (yet not tested).

That was only an example, it does not affect the site files at all.

Here is an example that would work for site:

'permissions' => [
    'panel.file.upload' => function($file) {

      if(
        $file->page()->isSite()
      ) {
        return false;
      } else {
        return true;
     }

    }
]

And instead of returning true or false, you can of course output your own messages.

1 Like

@texnixe:

Thank you very much for your code. I have tested it now. It works like you sayed :joy:

[edit: look at a newer post. The code effects all pages]

I think, someone should add this example in the Docs…
I suggest to add a link at the panel.site.upload Doc page to that code in the Docs.

There is no panel.site.upload options as there is not panel.page.upload option. All this is handled via the panel.file.upload option. I corrected my post above!

But I don’t understand, why I should code

If I add your code to the file site/roles/editor.php I think, I don’t need this part of your code.
If I add it to another role, it must be corrected.

Am I wrong?

I think you can leave that line out, as you are in a particular role anyway.

@texnixe:
Sorry, my test was not correct. The code effects all pages, not only the “Site options” page!

Yeah, I just realized the same, sorry.

$file->site()

does not seem to work either. I’ve invited @lukasbestle to the thread.

Ok, this way it should finally work:

<?php

return [
  'name'        => 'Editor',
  'default'     => true,
  'permissions' => [
    '*'                 => true,
  'panel.file.upload' => function() {

  if($this->target()->site()) {
    return false;
  } else {
    return true;
  }

}
  ]
];

1 Like

The condition

runs correct.

But if I change the condition to “$this->target()->page()->isSite()”, then it runs too, but your condition is shorter and more easy.

Thank you very much for your help, @texnixe and @lukasbestle.

Correction:

If I use

this setting does NOT work on panel pages like
http://example.com/panel/site/file/<filename.ext>/edit
for the most of the file permissions.

So I will use “$this->target()->page()->isSite()” instead, which works correct.