Skip to content

Commit 2691c83

Browse files
authored
Merge pull request #15 from topcoder-platform/issues-105
Issues-105, Issues-94
2 parents 5e2a638 + a594c9c commit 2691c83

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

class.groups.plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private function getTopcoderRoles($user, $resources = null, $roleResources = nul
407407
*/
408408
private function addGroupLinkToMenu() {
409409
if(Gdn::session()->isValid()) {
410-
echo '<li>'. anchor('Groups', GroupsPlugin::GROUPS_ROUTE).'</li>';
410+
echo '<li>'. anchor('Challenges', GroupsPlugin::GROUPS_ROUTE).'</li>';
411411
}
412412
}
413413

controllers/api/GroupsApiController.php

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ public function post(array $body) {
135135
return $result;
136136
}
137137

138+
/**
139+
* Update a group.
140+
*
141+
* @param array $body The request body.
142+
* @throws ServerException if the group could not be updated.
143+
* @return array
144+
*/
145+
public function patch($id, array $body) {
146+
$in = $this->groupPatchSchema()->setDescription('Update a group.');
147+
$out = $this->groupSchema('out');
148+
$body = $in->validate($body);
149+
$group = $this->groupModel->getByGroupID($id);
150+
if(!$group) {
151+
throw new NotFoundException('Group');
152+
}
153+
$group->Name = $body['name'];
154+
$result = $this->groupModel->save($group);
155+
$this->validateModel($this->groupModel);
156+
if ($result == false) {
157+
throw new ServerException('Unable to update a group.', 500);
158+
}
159+
$row = $this->groupModel->getID($id, DATASET_TYPE_ARRAY);
160+
return $out->validate($row);
161+
}
162+
138163
/**
139164
* Add participants to a group.
140165
*
@@ -251,7 +276,7 @@ public function groupSchema($type = '') {
251276
}
252277

253278
/**
254-
* Get a group schema with minimal add/edit fields.
279+
* Get a group schema with minimal add fields.
255280
*
256281
* @param string $type The type of schema.
257282
* @return Schema Returns a schema object.
@@ -268,6 +293,17 @@ public function groupPostSchema() {
268293
]), 'GroupPost');
269294
}
270295

296+
/**
297+
* Get a group schema with minimal edit fields.
298+
*
299+
* @param string $type The type of schema.
300+
* @return Schema Returns a schema object.
301+
*/
302+
public function groupPatchSchema() {
303+
return $this->schema(Schema::parse([
304+
'name:s' => 'The name of the group.',
305+
]), 'GroupPatch');
306+
}
271307

272308
/**
273309
* Get a schema instance comprised of all available group fields.

openapi/groups.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ paths:
8282
tags:
8383
- Groups
8484
summary: Get a group.
85+
patch:
86+
parameters:
87+
- description: The group ID.
88+
in: path
89+
name: id
90+
required: true
91+
schema:
92+
type: integer
93+
responses:
94+
'200':
95+
content:
96+
'application/json':
97+
schema:
98+
$ref: '#/components/schemas/Group'
99+
description: Success
100+
tags:
101+
- Groups
102+
requestBody:
103+
content:
104+
application/json:
105+
schema:
106+
$ref: '#/components/schemas/GroupPatch'
107+
required: true
108+
summary: Update a group.
85109
'/groups/{id}/members/{userid}':
86110
delete:
87111
parameters:
@@ -132,6 +156,12 @@ components:
132156
schema:
133157
$ref: '#/components/schemas/GroupPost'
134158
required: true
159+
GroupPatch:
160+
content:
161+
application/json:
162+
schema:
163+
$ref: '#/components/schemas/GroupPatch'
164+
required: true
135165
schemas:
136166
Group:
137167
properties:
@@ -195,6 +225,15 @@ components:
195225
- challengeID
196226
- challengeUrl
197227
type: object
228+
GroupPatch:
229+
properties:
230+
name:
231+
description: The name of the group.
232+
minLength: 1
233+
type: string
234+
required:
235+
- name
236+
type: object
198237
GroupMemberPost:
199238
description: Add a member to a group
200239
properties:

0 commit comments

Comments
 (0)