Core: Enabling endless shares when creating shares with POST request although default expiration date is set

Created on 15 May 2018  路  6Comments  路  Source: owncloud/core

In my application scenario a public link should be created via a POST request which should have no expiration.
However, in the given ownCloud instance there exist a default expiration Date.
The file files_sharing/lib/API/Share20OCS.php checks the transfered parameter like that :

//Expire date
      $expireDate = $this->request->getParam('expireDate', '');

       if ($expireDate !== '') {
           try {
                 $expireDate = $this->parseDate($expireDate);
                 $share->setExpirationDate($expireDate);
           } catch (\Exception $e) {
                 $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
                return new \OC\OCS\Result(null, 404, $this->l->t('Invalid date, date format must be YYYY-MM-DD'));
          }
      }

I see no way to pass a parameter to writhe no date into the database.

Steps to reproduce

  1. Create POST request with share params
  2. Set the expirationDate to emptyString ''
  3. Check whether the expirationDate is neglected

Expected behaviour

If an empty string is passed no expiration Date should be set for the given share.
I would expect somthing similar to update share where expireDate is handeled as follows:

if ($expireDate === '') {
       $share->setExpirationDate(null);
} else if ($expireDate !== null) {
       try {
              $expireDate = $this->parseDate($expireDate);
       } catch (\Exception $e) {
               $share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
               return new \OC\OCS\Result(null, 400, $e->getMessage());
       }
       $share->setExpirationDate($expireDate);
}

Actual behaviour

The default expiration Date is set.

bug-analysis acceptance-tests sharing

All 6 comments

"However, in the given ownCloud instance there exist a default expiration Date." Do you mean that the config parameter: default expiration date is set but enforce is not set, like in this screenshot?
image
Or is enforce set? config.report should tell. In which case you can't work without a date.

Enforce is not set.

As a dev using the OCS API I'd expect that whenever a field is not set at all in the POST, the default value is used. If I set a field to empty string, it means I explicitly want it to be empty.

So this could be a bug. Considering that the OCS Share API is based on older code it is possible that the default handling is a bit messed up. Needs further investigation.

As a dev using the OCS API I'd expect that whenever a field is not set at all in the POST, the default value is used. If I set a field to empty string, it means I explicitly want it to be empty.

I agree, it should be. At least, I think that two routes that do a similar thing (in this case: create and update) should behave similarly, which they don't. It would be great to be able to set the expiration date to empty string explicitly, without having to first create and then immediately update a share.

Hey, this issue has been closed because the label status/STALE is set and there were no updates for 7 days. Feel free to reopen this issue if you deem it appropriate.

(This is an automated comment from GitMate.io.)

It should be easy enough to write and acceptance test scenario for this and similar. I added the acceptance-tests label so I can find this issue.

Was this page helpful?
0 / 5 - 0 ratings