Skip to content

Issues-105, Issues-94 #15

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

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion class.groups.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private function getTopcoderRoles($user, $resources = null, $roleResources = nul
*/
private function addGroupLinkToMenu() {
if(Gdn::session()->isValid()) {
echo '<li>'. anchor('Groups', GroupsPlugin::GROUPS_ROUTE).'</li>';
echo '<li>'. anchor('Challenges', GroupsPlugin::GROUPS_ROUTE).'</li>';
}
}

Expand Down
38 changes: 37 additions & 1 deletion controllers/api/GroupsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ public function post(array $body) {
return $result;
}

/**
* Update a group.
*
* @param array $body The request body.
* @throws ServerException if the group could not be updated.
* @return array
*/
public function patch($id, array $body) {
$in = $this->groupPatchSchema()->setDescription('Update a group.');
$out = $this->groupSchema('out');
$body = $in->validate($body);
$group = $this->groupModel->getByGroupID($id);
if(!$group) {
throw new NotFoundException('Group');
}
$group->Name = $body['name'];
$result = $this->groupModel->save($group);
$this->validateModel($this->groupModel);
if ($result == false) {
throw new ServerException('Unable to update a group.', 500);
}
$row = $this->groupModel->getID($id, DATASET_TYPE_ARRAY);
return $out->validate($row);
}

/**
* Add participants to a group.
*
Expand Down Expand Up @@ -251,7 +276,7 @@ public function groupSchema($type = '') {
}

/**
* Get a group schema with minimal add/edit fields.
* Get a group schema with minimal add fields.
*
* @param string $type The type of schema.
* @return Schema Returns a schema object.
Expand All @@ -268,6 +293,17 @@ public function groupPostSchema() {
]), 'GroupPost');
}

/**
* Get a group schema with minimal edit fields.
*
* @param string $type The type of schema.
* @return Schema Returns a schema object.
*/
public function groupPatchSchema() {
return $this->schema(Schema::parse([
'name:s' => 'The name of the group.',
]), 'GroupPatch');
}

/**
* Get a schema instance comprised of all available group fields.
Expand Down
39 changes: 39 additions & 0 deletions openapi/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,30 @@ paths:
tags:
- Groups
summary: Get a group.
patch:
parameters:
- description: The group ID.
in: path
name: id
required: true
schema:
type: integer
responses:
'200':
content:
'application/json':
schema:
$ref: '#/components/schemas/Group'
description: Success
tags:
- Groups
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupPatch'
required: true
summary: Update a group.
'/groups/{id}/members/{userid}':
delete:
parameters:
Expand Down Expand Up @@ -132,6 +156,12 @@ components:
schema:
$ref: '#/components/schemas/GroupPost'
required: true
GroupPatch:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupPatch'
required: true
schemas:
Group:
properties:
Expand Down Expand Up @@ -195,6 +225,15 @@ components:
- challengeID
- challengeUrl
type: object
GroupPatch:
properties:
name:
description: The name of the group.
minLength: 1
type: string
required:
- name
type: object
GroupMemberPost:
description: Add a member to a group
properties:
Expand Down