feat: Add simplified admin API for circle/team management#2434
feat: Add simplified admin API for circle/team management#2434Sam428-png wants to merge 1 commit intonextcloud:masterfrom
Conversation
0ae8207 to
eb830b3
Compare
cristianscheid
left a comment
There was a problem hiding this comment.
@Sam428-png thanks a lot for taking the time to implement this PR, really appreciated! I tested it locally and left a couple of suggestions inline. I also have one more to add: looking at how other controllers are named and structured, I think it would make sense to merge CircleApiController and MemberApiController into a single file called AdminApiController, and rename CirclesAdminService to AdminApiService for consistency. Thanks again!
Sam428-png
left a comment
There was a problem hiding this comment.
Thanks, all feedback addressed!
|
Hi @cristianscheid, thanks again for the thorough review! While implementing your suggestion for |
Hey @Sam428-png, thank you for taking the time for this PR! Given the situation you just described, maybe we could do something like this then? // instead of
if ($federated) {
$updates['config'] = $federatedConfigValue;
}
// something like
$updates['config'] = $federated ? $federatedConfigValue : 0;Does that make sense to you? |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
|
Thanks for the feedback, and apologies for the late reply! This is now fixed in 9ff06b3 — |
There was a problem hiding this comment.
@Sam428-png thanks for the adjustments! One more thing I caught after re-review: since $updates will now always be non-empty, there's no longer need for the if (!empty($updates)) check anymore.
|
Thanks! Applied the suggestion in ea44975 — the empty-updates guard is gone and |
|
Thanks @Sam428-png! Could you please squash your commits into one and sign off? Only the first commit has a sign-off. |
ea44975 to
e0a8e89
Compare
|
Done! Squashed into a single commit with sign-off. |
Adds /admin/manage/ endpoints that allow admins to fully manage
circles (teams) without needing to be a member. Unlike the existing
/admin/{emulated}/ endpoints which require user emulation, these
endpoints use super sessions to operate directly as admin.
New endpoints:
- GET/POST/PUT/DELETE /admin/manage/circles — CRUD for circles
- GET/POST/DELETE /admin/manage/circles/{id}/members — member management
- PUT /admin/manage/circles/{id}/members/{id}/level — set member level
Based on the SURF circlesadmin app (sara-nl/nextcloud-circleadmin-api).
Signed-off-by: Sam428-png <s.d.ditmeijer@hva.nl>
e0a8e89 to
31c36df
Compare
|
Hi @cristianscheid, thanks for the thorough reviews! All feedback from the latest round has been applied in 31c36df:
Squashed into a single signed-off commit. Ready for another look! |
After internal discussion and looking at our codebase again, more specifically at our existing admin routes, I see that it's already possible to manage circles without being a member of them. If you make requests as admin and specify the circle's owner user id, you can manage the circle. Functionality wise, I think the only new feature that this PR would include is the ability to list all circles in a single endpoint without having to specify a user. Currently our ## already existing routes in circles/appinfo/routes.php
# get circles that user is part of
curl -X GET \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<user_id>/circles"
# get circle details
curl -X GET \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>"
# create new circle
curl -X POST \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
-H "Content-Type: application/json" \
-d '{"name":"<circle_name>"}' \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles"
# set circle name
curl -X PUT \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
-H "Content-Type: application/json" \
-d '{"value":"<circle_name>"}' \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/name"
# set circle description
curl -X PUT \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
-H "Content-Type: application/json" \
-d '{"value":"<description>"}' \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/description"
# set circle config (e.g. enable federation: Circle::CFG_ROOT + Circle::CFG_FEDERATED = 40960)
curl -X PUT \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
-H "Content-Type: application/json" \
-d '{"value":40960}' \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/config"
# remove circle
curl -X DELETE \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>"
# get circle members
curl -X GET \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/members"
# add member
curl -X POST \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
-H "Content-Type: application/json" \
-d '{"userId":"<user_id>","type":<member_type>}' \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/members"
# remove member
curl -X DELETE \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/members/<member_id>"
# set member level
curl -X PUT \
-u "admin:admin" \
-H "OCS-APIRequest: true" \
-H "Content-Type: application/json" \
-d '{"level":<member_level>}' \
"http://nextcloud.local/ocs/v2.php/apps/circles/admin/<owner_user_id>/circles/<circle_id>/members/<member_id>/level" |
Summary
/manage/API endpoints that allow Nextcloud admins to fully manage circles (teams) without needing to be a member of the circle/admin/{emulated}/endpoints which require user emulation per request, these endpoints use super sessions to operate directly as adminNew endpoints
GET/manage/circlesGET/manage/circles/{circleId}POST/manage/circlesname,owner,desc,federated)PUT/manage/circles/{circleId}DELETE/manage/circles/{circleId}GET/manage/circles/{circleId}/membersPOST/manage/circles/{circleId}/membersDELETE/manage/circles/{circleId}/members/{memberId}PUT/manage/circles/{circleId}/members/{memberId}/levelFiles added/changed
lib/Service/CirclesAdminService.php— business logic usingCirclesManagersuper/occ sessionslib/Controller/CircleApiController.php— circle CRUD endpoints (@AdminRequired)lib/Controller/MemberApiController.php— member management endpoints (@AdminRequired)appinfo/routes.php— 9 new OCS routes under/manage/Test plan
GET /manage/circles— returns list of all circlesPOST /manage/circles— create local circle with descriptionPOST /manage/circleswithfederated=1— create federated circle (config=0)GET /manage/circles/{id}— returns circle detail with members arrayPUT /manage/circles/{id}— update name and descriptionDELETE /manage/circles/{id}— delete circlePOST /manage/circles/{id}/members— add member to circleGET /manage/circles/{id}/members— list all membersPUT /manage/circles/{id}/members/{id}/level— change member levelDELETE /manage/circles/{id}/members/{id}— remove memberAll endpoints tested on Nextcloud 32 and Nextcloud 33 instances.