server icon indicating copy to clipboard operation
server copied to clipboard

OCS Share API - "permissions" parameter has no effect

Open kepon85 opened this issue 6 years ago • 9 comments

Hello,

Thank's for Nextcloud !

I am the documentation : https://docs.nextcloud.com/server/stable/developer_manual/client_apis/OCS/ocs-share-api.html#create-a-new-share

I'm looking to create the share of a write-enabled file with the OCS Share API

But the "permissions" parameter seems to have no effect ...

My code :

$cURLConnection = curl_init();
$params=array (
    'path' => './t1.md',
    'shareType' => 3,
    'permissions' => 19,
    'password' => ''
);
curl_setopt($cURLConnection, CURLOPT_URL, 'https://'.$username.':'.$password.'@'.$nextcloud_hostname.'/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json');
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
    'OCS-APIRequest: true'
));
curl_setopt($cURLConnection, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $params);
$phoneList = curl_exec($cURLConnection);
curl_close($cURLConnection);
$jsonArrayResponse = json_decode($phoneList);
var_dump($jsonArrayResponse);

The var_dump say permissions = 17 :-/

object(stdClass)#4 (1) {
  ["ocs"]=>
  object(stdClass)#2 (2) {
    ["meta"]=>
    object(stdClass)#1 (3) {
      ["status"]=>
      string(2) "ok"
      ["statuscode"]=>
      int(200)
      ["message"]=>
      string(2) "OK"
    }
    ["data"]=>
    array(1) {
      [0]=>
      object(stdClass)#3 (31) {
        ["id"]=>
        string(2) "57"
        ["share_type"]=>
        int(3)
        ["uid_owner"]=>
        string(5) "david"
        ["displayname_owner"]=>
        string(5) "david"
        ["permissions"]=>
        int(17)
[...]
}

If I manually change the file permission in nextcloud (write permission), then I GET the share (https://docs.nextcloud.com/server/stable/developer_manual/client_apis/OCS/ocs-share- api.html # get-information-about-a-known-share) I get permissions = 19 :

object(stdClass)#4 (1) {
  ["ocs"]=>
  object(stdClass)#2 (2) {
    ["meta"]=>
    object(stdClass)#1 (3) {
      ["status"]=>
      string(2) "ok"
      ["statuscode"]=>
      int(200)
      ["message"]=>
      string(2) "OK"
    }
    ["data"]=>
    array(1) {
      [0]=>
      object(stdClass)#3 (31) {
        ["id"]=>
        string(2) "57"
        ["share_type"]=>
        int(3)
        ["uid_owner"]=>
        string(5) "david"
        ["displayname_owner"]=>
        string(5) "david"
        ["permissions"]=>
        int(19)

I tried with the value 1, 2, 10, 31 ... none seems to have an effect ... yet the rest of the arguments have an effect (password for example)

I guess it's a bug ...

Nextcloud 19.0.3 / Apache / PHP 7.3 / Mysql

kepon85 avatar Oct 02 '20 19:10 kepon85

I can add that some of check is done, because when entering arbitary number (permissons=100) i get error

<?xml version="1.0"?>
<ocs>
 <meta>
  <status>failure</status>
  <statuscode>404</statuscode>
  <message>invalid permissions</message>
 </meta>
 <data/>
</ocs>

Otherwise Share permission is always 1 (read only)

Same experience in Nextcloud 20.0.8RC1.

Have you tried 20.0.8 stable release, @kepon85 ?

vahem2lu avatar Mar 09 '21 08:03 vahem2lu

Hi there, can you please post your question in https://help.nextcloud.com/c/dev/11 thats the better place for this. Thanks!

szaimen avatar Jun 25 '21 12:06 szaimen

It's rather than a bug, no?

vahem2lu avatar Jun 28 '21 06:06 vahem2lu

Did you find any solution for this?

aremesch avatar Aug 02 '21 10:08 aremesch

If you do an unshare first and the share, the permissions will be set correctly. If you just re-share an existing share the permissions will stay as set the first time without returning an error. Observed in NC 21.0.2

aremesch avatar Aug 02 '21 10:08 aremesch

I had the same issue with different versions of nextcloud.

As a workaround, I'm creating the share and set the permissions with Update Share PUT command afterwards. But you have to get the share_id from the output of the creation command

That works fine. I hope this helps some of you!

nachter avatar May 04 '22 20:05 nachter

Not solved yet, hello? Why closed?

timowevel1 avatar May 25 '22 10:05 timowevel1

but the ocs update api is also not working

Tarun123-kittu avatar May 25 '22 13:05 Tarun123-kittu

FTR, there is a new version of this bug report: #32611

jplitza avatar Nov 16 '22 11:11 jplitza