Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAV endpoint #7

Merged
merged 3 commits into from
Feb 3, 2017
Merged

DAV endpoint #7

merged 3 commits into from
Feb 3, 2017

Conversation

PVince81
Copy link
Contributor

@PVince81 PVince81 commented Dec 6, 2016

This PR is based on top of #1.

This adds DAV endpoints for #3

@PVince81 PVince81 added this to the 9.2 milestone Dec 6, 2016
@CLAassistant
Copy link

CLAassistant commented Dec 6, 2016

CLA assistant check
All committers have signed the CLA.

@PVince81
Copy link
Contributor Author

Rebased, added lots of tests.

A few calls and conditions are missing still.

@PVince81
Copy link
Contributor Author

Already implemented the main part of the spec #3 for managing groups and memberships.

Next step: REPORT

@PVince81 PVince81 changed the title [WIP] DAV endpoint DAV endpoint Dec 13, 2016
@PVince81
Copy link
Contributor Author

I've added the REPORT as well:

Here is how to get one.
Put this into report-customgroups.xml:

<?xml version="1.0" encoding="utf-8" ?>
<oc:filter-members xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns" >
	<oc:filter-rules>
		<oc:user-id>user1</oc:user-id>
		<!--	<oc:is-admin>1</oc:is-admin> -->
	</oc:filter-rules>
</oc:filter-members>

Then curl -u admin:admin -X REPORT -H "Content-Type: text/xml" --data-binary "@report-customgroups.xml" 'http://localhost/owncloud/remote.php/dav/customgroups/'

Gives:

<?xml version="1.0"?>
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cal="urn:ietf:params:xml:ns:caldav" xmlns:cs="http://calendarserver.org/ns/" xmlns:card="urn:ietf:params:xml:ns:carddav" xmlns:oc="http://owncloud.org/ns">
 <d:response>
  <d:status>HTTP/1.1 200 OK</d:status>
  <d:href>/owncloud/remote.php/dav/customgroups/x/user1</d:href>
  <d:propstat>
   <d:prop>
    <oc:is-admin>0</oc:is-admin>
   </d:prop>
   <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
 </d:response>
 <d:response>
  <d:status>HTTP/1.1 200 OK</d:status>
  <d:href>/owncloud/remote.php/dav/customgroups/y/user1</d:href>
  <d:propstat>
   <d:prop>
    <oc:is-admin>0</oc:is-admin>
   </d:prop>
   <d:status>HTTP/1.1 200 OK</d:status>
  </d:propstat>
 </d:response>
</d:multistatus>

It basically returns the result for the CustomGroupMemberNode. I'm not too happy about this because it will not be useful for the UI. It misses the group display name and the group URI. Well, the group URI can be extracted from the result path.

I'd like to refine this separately once we start working on the UI.

@PVince81
Copy link
Contributor Author

PVince81 commented Dec 13, 2016

  • make it possible for regular admins to do the same things like group admins

The sad thing about adding this is that now I need to inject a group manager everywhere...

/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- .


$memberInfos = $this->node->getChildren();

$this->assertInstanceOf('\OCA\CustomGroups\Dav\CustomGroupMemberNode', $memberInfos[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CustomGroupMemberNode::class

*
* This method should set up the required event subscriptions.
*
* @param Server $server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server is unknown

* @param [] $report
* @param string $uri
* @return bool
* @throws NotFound
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotFound is unknown

* @param string $uri
* @return bool
* @throws NotFound
* @throws ReportNotSupported
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReportNotSupported is unknown

public function onReport($reportName, $report, $uri) {
$node = $this->server->tree->getNodeForPath($uri);
if(!$node instanceof RootCollection || $reportName !== self::REPORT_NAME) {
throw new ReportNotSupported();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReportNotSupported is unknown

/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @copyright Copyright (c) 2016, ownCloud GmbH.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the .

*/
private $userSession;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPDoc missing

/**
* Update the admin flag
*
* @param int $isAdminPropValue 1 for true, 0 for false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return tag is missing

@DeepDiver1975
Copy link
Member

It basically returns the result for the CustomGroupMemberNode. I'm not too happy about this because it will not be useful for the UI. It misses the group display name and the group URI. Well, the group URI can be extracted from the result path.

please have a look at the carddav query request - there is a node where you select the elements which you expect to be returned ...

https://tools.ietf.org/html/rfc6352#section-8.6.3

     <D:prop>
       <D:getetag/>
       <CG:display/>
     </D:prop>

@PVince81
Copy link
Contributor Author

Are you kidding me...

Analysing /home/travis/build/owncloud/core/apps/customgroups/lib/composer/composer/ClassLoader.php

 1 errors

    line  317: == - is discouraged

App is not compliant

make: *** [test-codecheck] Error 101

Will need to exclude the composer stuff from the code checker

@PVince81
Copy link
Contributor Author

Squashed and removed the composer files I checked in by mistake from the other branch.

@PVince81
Copy link
Contributor Author

ownCloud admins can now also manage groups even when they aren't members.

Instead of passing around yet another object IGroupManaber, I created a helper class instead MembershipHelper which takes care of checking whether the current user can or cannot manage stuff based on their role and memberships.

@PVince81
Copy link
Contributor Author

@DeepDiver1975 please re-review.

My next step is to adjust the REPORT to implement pagination, but this could also be done separately if this PR is already mergable.

@PVince81
Copy link
Contributor Author

I'm feeling a bit lazy with the REPORT + pagination especially if I need to do it for all the different endpoints. So I came up with this generic paginated report idea, please check it out: owncloud/core#26840

@PVince81
Copy link
Contributor Author

REPORT will be done in a separate PR.

@DeepDiver1975 please review


$this->server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
$ns = '{' . self::NS_OWNCLOUD . '}';
$this->server->resourceTypeMapping['OCA\\CustomGroups\\Dav\\MembershipNode'] = $ns . 'customgroups-membership';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and use ::class

public function createFile($userId, $data = null) {
$groupId = $this->groupInfo['group_id'];
if (!$this->helper->isUserAdmin($groupId)) {
throw new Forbidden('No permission to add members to group "' . $groupId . '"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use string interpolation for better readability

    throw new Forbidden("No permission to add members to group '$groupId'");

@DeepDiver1975
Copy link
Member

  • listing users does not work /remote.php/dav/customgroups/users/

@PVince81
Copy link
Contributor Author

listing users does not work /remote.php/dav/customgroups/users/

This is by design, same like the "users" list principal.

You need to know the user name you want to query.

@DeepDiver1975
Copy link
Member

This is by design, same like the "users" list principal.

Okay - in debug mode we allow listing of users in other collections as well

@PVince81
Copy link
Contributor Author

Okay - in debug mode we allow listing of users in other collections as well

Yet another code path to test / unit test and maintain. I'd rather not.

Unless we make it more useful by enabling user listing for any admins
And even then, the admin should be able to get a listing from the other endpoint.

Let me know what you think.

@PVince81
Copy link
Contributor Author

PVince81 commented Feb 2, 2017

Adjusted exception formatting.

Added missing case: ownCloud admin can now enter the "users/$userId" subcollection even if not a member.

@DeepDiver1975 I'd like to not add user listing here, it would require injecting the user manager, etc. I don't think it's useful enough, especially if only used in debug mode.

@DeepDiver1975 DeepDiver1975 merged commit ad4d5ab into master Feb 3, 2017
@DeepDiver1975 DeepDiver1975 deleted the dav-endpoint branch February 3, 2017 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants