-
Notifications
You must be signed in to change notification settings - Fork 7
breaking: Replace deprecated endpoints with the new ones CY-7670 #148
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,12 @@ package com.codacy.client.bitbucket.v2 | |
| import play.api.libs.functional.syntax._ | ||
| import play.api.libs.json._ | ||
|
|
||
| case class Workspace(uuid: String, slug: String, name: String, avatar: String) | ||
| case class Workspace(uuid: String, slug: String, avatar: String) | ||
|
|
||
| object Workspace { | ||
| implicit val reader: Reads[Workspace] = ( | ||
| (__ \ "uuid").read[String] and | ||
| (__ \ "slug").read[String] and | ||
| (__ \ "name").read[String] and | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use this field. And since it does not come on the list of workspaces now, it is cleaner to just remove it. This way can be used on both the listing of workspaces and the getting of the workspace |
||
| (__ \ "links" \ "avatar" \ "href").read[String] | ||
| )(Workspace.apply _) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.codacy.client.bitbucket.v2 | ||
|
|
||
| import play.api.libs.functional.syntax._ | ||
| import play.api.libs.json._ | ||
|
|
||
| /** | ||
| * Represents a user's access to a workspace from the /user/workspaces endpoint. | ||
| * | ||
| * @param administrator Whether the user has administrator access to the workspace | ||
| * @param workspace The workspace details | ||
| */ | ||
| case class WorkspaceAccess(administrator: Boolean, workspace: Workspace) | ||
|
|
||
| object WorkspaceAccess { | ||
| implicit val reader: Reads[WorkspaceAccess] = ( | ||
| (__ \ "administrator").read[Boolean] and | ||
| (__ \ "workspace").read[Workspace] | ||
| )(WorkspaceAccess.apply _) | ||
|
machadoit marked this conversation as resolved.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,7 @@ | ||
| package com.codacy.client.bitbucket.v2.service | ||
|
|
||
| import java.net.URLEncoder | ||
| import com.codacy.client.bitbucket.client.{ | ||
| BitbucketClient, | ||
| FailedResponse, | ||
| PageRequest, | ||
| RequestResponse, | ||
| SuccessfulResponse | ||
| } | ||
| import com.codacy.client.bitbucket.client.{BitbucketClient, RequestResponse} | ||
| import com.codacy.client.bitbucket.v2._ | ||
| import play.api.libs.json.Json | ||
|
|
||
|
|
@@ -26,26 +20,13 @@ class UserServices(client: BitbucketClient) { | |
| client.executePaginated[Email](s"${client.userBaseUrl}/emails") | ||
|
|
||
| /** | ||
| * Search for workspaceUUID among the workspaces that the current user is member of | ||
| * returns the workspace and their effective role | ||
| * Get the current user's permission on a specific workspace. | ||
| * Uses the new /user/workspaces/{workspace}/permission endpoint | ||
| * (replaces deprecated /user/permissions/workspaces). | ||
| */ | ||
| def getWorkspaceMembership(workspaceUUID: String): RequestResponse[WorkspacePermission] = { | ||
| val workspaceUUIDEncoded = URLEncoder.encode(s""""$workspaceUUID"""", "UTF-8") | ||
| val workspaceQuery = s"""workspace.uuid=$workspaceUUIDEncoded""" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clearly it was a nice change of endpoint. The fact that they now give the 'membership' information if we access the workspace via |
||
|
|
||
| client.executeWithCursor[WorkspacePermission]( | ||
| s"""${client.userBaseUrl}/permissions/workspaces?q=$workspaceQuery""", | ||
| PageRequest() | ||
| ) match { | ||
| case SuccessfulResponse(membership +: _, _, _, _, _, _) => | ||
| if (membership.team.uuid == workspaceUUID) { | ||
| SuccessfulResponse(membership) | ||
| } else { | ||
| FailedResponse(s"UUIDs don't match. Queried $workspaceUUID but received ${membership.team.uuid}") | ||
| } | ||
| case error: FailedResponse => error | ||
| case _ => FailedResponse(s"Couldn't find $workspaceUUID for the current user") | ||
| } | ||
| client.execute[WorkspacePermission](s"${client.userBaseUrl}/workspaces/$workspaceUUIDEncoded/permission") | ||
|
machadoit marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.