|
1 | 1 | package org.gitlab4j.api;
|
2 | 2 |
|
| 3 | +import java.util.Date; |
3 | 4 | import java.util.List;
|
4 | 5 |
|
5 | 6 | import javax.ws.rs.core.Form;
|
6 | 7 | import javax.ws.rs.core.GenericType;
|
7 | 8 | import javax.ws.rs.core.Response;
|
8 | 9 |
|
9 | 10 | import org.gitlab4j.api.GitLabApi.ApiVersion;
|
| 11 | +import org.gitlab4j.api.models.AccessLevel; |
10 | 12 | import org.gitlab4j.api.models.Group;
|
11 | 13 | import org.gitlab4j.api.models.Member;
|
12 | 14 | import org.gitlab4j.api.models.Project;
|
@@ -359,32 +361,146 @@ public Member getMember(int groupId, int userId) throws GitLabApiException {
|
359 | 361 | *
|
360 | 362 | * POST /groups/:id/members
|
361 | 363 | *
|
362 |
| - * @param groupId the project ID to add the member to |
363 |
| - * @param userId the user ID of the member to add |
364 |
| - * @param accessLevel the access level for the new member |
| 364 | + * @param groupId the project ID to add the member to, required |
| 365 | + * @param userId the user ID of the member to add, required |
| 366 | + * @param accessLevel the access level for the new member, required |
365 | 367 | * @return a Member instance for the added user
|
366 | 368 | * @throws GitLabApiException if any exception occurs
|
367 | 369 | */
|
368 | 370 | public Member addMember(Integer groupId, Integer userId, Integer accessLevel) throws GitLabApiException {
|
| 371 | + return (addMember(groupId, userId, accessLevel, null)); |
| 372 | + } |
369 | 373 |
|
370 |
| - Form formData = new Form(); |
371 |
| - formData.param("user_id", userId.toString()); |
372 |
| - formData.param("access_level", accessLevel.toString()); |
| 374 | + /** |
| 375 | + * Adds a user to the list of group members. |
| 376 | + * |
| 377 | + * POST /groups/:id/members |
| 378 | + * |
| 379 | + * @param groupId the project ID to add the member to, required |
| 380 | + * @param userId the user ID of the member to add, required |
| 381 | + * @param accessLevel the access level for the new member, required |
| 382 | + * @return a Member instance for the added user |
| 383 | + * @throws GitLabApiException if any exception occurs |
| 384 | + */ |
| 385 | + public Member addMember(Integer groupId, Integer userId, AccessLevel accessLevel) throws GitLabApiException { |
| 386 | + return (addMember(groupId, userId, accessLevel.toValue(), null)); |
| 387 | + } |
| 388 | + |
| 389 | + /** |
| 390 | + * Adds a user to the list of group members. |
| 391 | + * |
| 392 | + * POST /groups/:id/members |
| 393 | + * |
| 394 | + * @param groupId the project ID to add the member to, required |
| 395 | + * @param userId the user ID of the member to add, required |
| 396 | + * @param accessLevel the access level for the new member, required |
| 397 | + * @param expiresAt the date the membership in the group will expire, optional |
| 398 | + * @return a Member instance for the added user |
| 399 | + * @throws GitLabApiException if any exception occurs |
| 400 | + */ |
| 401 | + public Member addMember(Integer groupId, Integer userId, AccessLevel accessLevel, Date expiresAt) throws GitLabApiException { |
| 402 | + return (addMember(groupId, userId, accessLevel.toValue(), expiresAt)); |
| 403 | + } |
| 404 | + |
| 405 | + /** |
| 406 | + * Adds a user to the list of group members. |
| 407 | + * |
| 408 | + * POST /groups/:id/members |
| 409 | + * |
| 410 | + * @param groupId the project ID to add the member to, required |
| 411 | + * @param userId the user ID of the member to add, required |
| 412 | + * @param accessLevel the access level for the new member, required |
| 413 | + * @param expiresAt the date the membership in the group will expire, optional |
| 414 | + * @return a Member instance for the added user |
| 415 | + * @throws GitLabApiException if any exception occurs |
| 416 | + */ |
| 417 | + public Member addMember(Integer groupId, Integer userId, Integer accessLevel, Date expiresAt) throws GitLabApiException { |
| 418 | + |
| 419 | + GitLabApiForm formData = new GitLabApiForm() |
| 420 | + .withParam("user_id", userId, true) |
| 421 | + .withParam("access_level", accessLevel, true) |
| 422 | + .withParam("expires_at", expiresAt, false); |
373 | 423 | Response response = post(Response.Status.CREATED, formData, "groups", groupId, "members");
|
374 | 424 | return (response.readEntity(Member.class));
|
375 | 425 | }
|
376 | 426 |
|
377 | 427 | /**
|
378 |
| - * Removes member from the group team. |
| 428 | + * Updates a member of a group. |
| 429 | + * |
| 430 | + * PUT /groups/:groupId/members/:userId |
| 431 | + * |
| 432 | + * @param groupId the group ID the member belongs to, required |
| 433 | + * @param userId the user ID of the member to update, required |
| 434 | + * @param accessLevel the new access level for the member, required |
| 435 | + * @return the updated member |
| 436 | + * @throws GitLabApiException if any exception occurs |
| 437 | + */ |
| 438 | + public Member updateMember(Integer groupId, Integer userId, Integer accessLevel) throws GitLabApiException { |
| 439 | + return (updateMember(groupId, userId, accessLevel, null)); |
| 440 | + } |
| 441 | + |
| 442 | + /** |
| 443 | + * Updates a member of a group. |
| 444 | + * |
| 445 | + * PUT /groups/:groupId/members/:userId |
| 446 | + * |
| 447 | + * @param groupId the group ID the member belongs to, required |
| 448 | + * @param userId the user ID of the member to update, required |
| 449 | + * @param accessLevel the new access level for the member, required |
| 450 | + * @return the updated member |
| 451 | + * @throws GitLabApiException if any exception occurs |
| 452 | + */ |
| 453 | + public Member updateMember(Integer groupId, Integer userId, AccessLevel accessLevel) throws GitLabApiException { |
| 454 | + return (updateMember(groupId, userId, accessLevel.toValue(), null)); |
| 455 | + } |
| 456 | + |
| 457 | + /** |
| 458 | + * Updates a member of a group. |
| 459 | + * |
| 460 | + * PUT /groups/:groupId/members/:userId |
| 461 | + * |
| 462 | + * @param groupId the group ID the member belongs to, required |
| 463 | + * @param userId the user ID of the member to update, required |
| 464 | + * @param accessLevel the new access level for the member, required |
| 465 | + * @param expiresAt the date the membership in the group will expire, optional |
| 466 | + * @return the updated member |
| 467 | + * @throws GitLabApiException if any exception occurs |
| 468 | + */ |
| 469 | + public Member updateMember(Integer groupId, Integer userId, AccessLevel accessLevel, Date expiresAt) throws GitLabApiException { |
| 470 | + return (updateMember(groupId, userId, accessLevel.toValue(), expiresAt)); |
| 471 | + } |
| 472 | + |
| 473 | + /** |
| 474 | + * Updates a member of a group. |
| 475 | + * |
| 476 | + * PUT /groups/:groupId/members/:userId |
| 477 | + * |
| 478 | + * @param groupId the group ID the member belongs to, required |
| 479 | + * @param userId the user ID of the member to update, required |
| 480 | + * @param accessLevel the new access level for the member, required |
| 481 | + * @param expiresAt the date the membership in the group will expire, optional |
| 482 | + * @return the updated member |
| 483 | + * @throws GitLabApiException if any exception occurs |
| 484 | + */ |
| 485 | + public Member updateMember(Integer groupId, Integer userId, Integer accessLevel, Date expiresAt) throws GitLabApiException { |
| 486 | + GitLabApiForm formData = new GitLabApiForm() |
| 487 | + .withParam("access_level", accessLevel, true) |
| 488 | + .withParam("expires_at", expiresAt, false); |
| 489 | + Response response = put(Response.Status.OK, formData.asMap(), "groups", groupId, "members", userId); |
| 490 | + return (response.readEntity(Member.class)); |
| 491 | + } |
| 492 | + |
| 493 | + /** |
| 494 | + * Removes member from the group. |
379 | 495 | *
|
380 | 496 | * DELETE /groups/:id/members/:user_id
|
381 | 497 | *
|
382 |
| - * @param projectId the project ID to remove the member from |
| 498 | + * @param groupId the group ID to remove the member from |
383 | 499 | * @param userId the user ID of the member to remove
|
384 | 500 | * @throws GitLabApiException if any exception occurs
|
385 | 501 | */
|
386 |
| - public void removeMember(Integer projectId, Integer userId) throws GitLabApiException { |
| 502 | + public void removeMember(Integer groupId, Integer userId) throws GitLabApiException { |
387 | 503 | Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
|
388 |
| - delete(expectedStatus, null, "groups", projectId, "members", userId); |
| 504 | + delete(expectedStatus, null, "groups", groupId, "members", userId); |
389 | 505 | }
|
390 | 506 | }
|
0 commit comments