Skip to content
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

update models with updated permission enum #2633

Merged
merged 47 commits into from
Jan 20, 2023

Conversation

notauserx
Copy link
Contributor

@notauserx notauserx commented Dec 5, 2022

Resolves #2323


Behavior

Before the change?

  • NewTeam, UpdateTeam on the request side and the Team on the response side uses incorrect permission enums

After the change?

Based on the schema

  • Fix permission enum for NewTeam(line 11249), UpdateTeam(line 11418).
  • Update "Permission" and "Permissions" properties on Team.cs (line 62414)

Other information

  • I have also added the following endpoints from the teams api because TeamsClient was using the legacy ones and are closely related to Team Permissions

Additional info

Pull request checklist

  • Tests for the changes have been added
  • Docs have been reviewed and added/updated if needed
  • Added the appropriate label for the given change
  • Decide what to do with the UpdateTeam model, looks like it uses the legacy update team schema
  • Mark areas with breaking changes
  • Update integration tests.

Does this introduce a breaking change?

  • Yes (Please add the Type: Breaking change label)
  • Changes to the request(NewTeam.cs, UpdateTeam.cs) and response(Team.cs) model

  • Changed Permission property type from Permission to TeamPermission on NewTeam and UpdateTeam request models

  • Changed Permission property type from StringEnum to string

Pull request type

  • Type: Bug
  • Type: Breaking Change

@notauserx
Copy link
Contributor Author

I have added two new enums, NewTeamPermission and TeamPermission to model the enum values from the openapi schema. Also, updated the NewTeam.cs to use the NewTeamPermission, and UpdateTeam.cs and Team.cs to use TeamPermission.

I am having some trouble running the integration tests for TeamsClientTests, all the tests are marked with OrganizationTest. I have added an organization to my test account for integration, is there a setup doc that I am missing?

Also, I see that the permission is marked as Deprecated on the docs as well as the rest open api schema. Are these permissions getting deprecated?

@notauserx notauserx changed the title update models with updated permission enum [wip] update models with updated permission enum Dec 5, 2022
@kfcampbell
Copy link
Member

I am having some trouble running the integration tests for TeamsClientTests, all the tests are marked with OrganizationTest. I have added an organization to my test account for integration, is there a setup doc that I am missing?

How are you attempting to run the tests? What platform are you doing it on? The only doc I'm aware of that's relevant is this one.

Also, I see that the permission is marked as Deprecated on the docs as well as the rest open api schema. Are these permissions getting deprecated?

I don't have any cool insider information here, sorry. I would guess if they're marked as deprecated, they will be deprecated, but I'm not sure of the timeframe.

@notauserx
Copy link
Contributor Author

@kfcampbell, thanks for your response, I guess I did not provide enough context for my problem.

Figured out the issue, I had not set the OCTOKIT_GITHUBORGANIZATION environment variable and the OrganizationTests requires that variable be set.

@@ -445,10 +446,14 @@ public async Task UpdatesTeam()
{
var teamName = Helper.MakeNameWithTimestamp("updated-team");
var teamDescription = Helper.MakeNameWithTimestamp("updated description");

// setting TeamPermission.Admin fails with Octokit.ApiValidationException : Setting team permission to admin is no longer supported
var teamPermission = TeamPermission.Push;
Copy link
Contributor Author

@notauserx notauserx Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that admin is not being accepted as a permission value, even though the docs say it can be.

I can get this test passing with Pull and Push values, but passing admin just fails with

setting TeamPermission.Admin fails with Octokit.ApiValidationException : Setting team permission to admin is no longer supported

curl also gets me the same error

{
  "message": "Setting team permission to admin is no longer supported",
  "documentation_url": "https://docs.github.com/rest/reference/teams/#update-a-team-legacy"
}

@notauserx
Copy link
Contributor Author

What I propose is we make TeamPermission enum with pull and push values, and use that in NewTeam, UpdateTeam and Team classes. I can see that when you edit and Organization from the web UI, there is no option to set the permission, I am guessing since the permission is marked as deprecated, they don't a.

I have kept both the current and legacy versions for Update a team and Delete a team, as can be seen in the ITeamsClient, I have renamed the Update and Delete contract as UpdateLegacy and DeleteLegacy respectively, and created Update and Delete contracts that exposes the current endpoint. Not sure whether to keep the legacy endpoints exposed but I think we can leave that on the ITeamsContract.

Also, not dealing with RepositoryPermissions (also called ReviewPermissions) for collaborators as @nickfloyd mentioned in the issue, want to tackle it in a separate PR.

Hopefully, I am moving in the right direction with this PR, let me know what you think.

@kfcampbell
Copy link
Member

What I propose is we make TeamPermission enum with pull and push values, and use that in NewTeam, UpdateTeam and Team classes.

This sounds like a reasonable solution to me. I always get confused by the push/pull and read/write permission splits.

Not sure whether to keep the legacy endpoints exposed

My vote is to keep the legacy behavior around in the SDK until it's dropped by the API.

Also, not dealing with RepositoryPermissions (also called ReviewPermissions) for collaborators as @nickfloyd mentioned in the issue, want to tackle it in a separate PR.

👍

This direction makes sense to me.

@notauserx
Copy link
Contributor Author

notauserx commented Dec 7, 2022

Here's a summary of my changes so far

  • Created TeamPermission enum for creating and updating team request model.
  • Found that both update and delete teams were using legacy endpoints, so added support for current endpoints for updating and deleting a team.
  • Found a schema inconsistency with the update of a team endpoint where "admin" was not being supported as a permission value, contrary to what the doc says. Created an issue.
  • Added TeamRepositoryPermission enum and TeamRepositoryPermissions object to model the permission and permissions property of the team response model. These were based on the schema
  • Deleted TeamRepositoryPermission enum and changed the type of Permission property on Team.cs as string to reflect the schema
      "permission": {
        "type": "string"
      },
      "permissions": {
        "type": "object",
        "properties": {
          "pull": {
            "type": "boolean"
          },
          "triage": {
            "type": "boolean"
          },
          "push": {
            "type": "boolean"
          },
          "maintain": {
            "type": "boolean"
          },
          "admin": {
            "type": "boolean"
          }
        },
        "required": [
          "pull",
          "triage",
          "push",
          "maintain",
          "admin"
        ]
      },

.editorconfig Outdated
@@ -0,0 +1,3 @@
root = true
[*.cs]
end_of_line = lf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this file because I was having trouble with inconsistent line ending.

I can remove this file if necessary. But I think having an editorconfig file greatly improves the dev experience. This one is by no means complete.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that this is added in a separate PR if you don't mind.

Copy link
Contributor Author

@notauserx notauserx Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable. Removed the file and set a global gitignore for my local editorconfig

@kfcampbell kfcampbell added the Type: Breaking change Used to note any change that requires a major version bump label Dec 14, 2022
@kfcampbell
Copy link
Member

is there a naming convention that we follow for naming the methods, or what to return for a 204 status code on the response?

Not to my knowledge, though perhaps @nickfloyd has opinions on this matter?

I think we could choose either the "operationId" or the "summary" value to name the method in the clients, I personally prefer the "summary" because that's more accessible from the docs . What do you think?

👍

how/where do I mark the breaking changes?

I've added the "Type: Breaking Change" label to this PR. When releasing a new version, we'll have to be careful to increment to v5.0.0 as well.

Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing! I have several naive questions, I hope that's okay.

.editorconfig Outdated
@@ -0,0 +1,3 @@
root = true
[*.cs]
end_of_line = lf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer that this is added in a separate PR if you don't mind.

/// <summary>
/// Delete a team - must have owner permissions to do this
/// This endpoint route is deprecated and will be removed from the Teams API.
/// We recommend migrating your existing code to use the new Delete a team endpoint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are your thoughts on providing a link or some other manner to direct users towards the new endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great suggestion. I will provide a link to the new endpoint in the comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, looking forward to it!

Copy link
Contributor Author

@notauserx notauserx Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a link

@@ -70,7 +70,8 @@ public void NoStalePreviews()
// https://developer.github.com/v3/repos/commits/#get-a-single-commit
"application/vnd.github.v3.sha",
// https://developer.github.com/v3/activity/starring/#alternative-response-with-star-creation-timestamps
"application/vnd.github.v3.star+json"
"application/vnd.github.v3.star+json",
"application/vnd.github.v3.repository+json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind explaining to me the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added RepositoryContentMediaType to AcceptHeaders for passing repository media type in CheckTeamPermissionsForARepositoryWithCustomAcceptHeader. This caused this convention test to fail because now it expects "application/vnd.github.v3.repository+json" in defaultHeaders

/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="organization">Org to associate the repo with.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="permission">The permission to grant the team on this repository.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
[ManualRoute("PUT", "/orgs/{org}/team/{team_slug}/repos/{owner}/{repo}")]
[ManualRoute("PUT", "/teams/{team_id}/repos/{owner}/{repo}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason you went with the strategy of changing routes here and adding new ones with a different method name to the client?

I'm naively thinking it might be easier to avoid a breaking change here by isolating the new functionality to new methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the legacy endpoint that is currently implemented in the project, however, it gets the endpoint uri from ApiUrls.TeamRepository which returns the /teams/{team_id}/repos/{owner}/{repo}, so I've decided to update the ManualRoute attribute value to match the correct url from the docs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, thanks for explaining! @nickfloyd has mentioned to me that ManualRoute is used for documentation generation rather than implementation, so this makes sense.

/// <param name="uri">URI of the API resource to put</param>
/// <param name="data">Object that describes the API resource; this will be serialized and used as the request's body</param>
/// <returns>A <see cref="Task"/> for the request's execution.</returns>
public Task Put(Uri uri, object data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind ELI5ing the reason for this helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed a non-generic Put method where I could pass data for the request's body for AddOrUpdateTeamRepositoryPermissions method on TeamsClients, which returns a 204.

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
@notauserx
Copy link
Contributor Author

Thank you for contributing! I have several naive questions, I hope that's okay.

I am glad you took the time to review and give me some feedback. Appreciate it!

@notauserx notauserx changed the title [wip] update models with updated permission enum update models with updated permission enum Dec 17, 2022
Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your patience! @nickfloyd and I had a few more questions on this review for you before we get this wrapped up. Looking forward to getting the PR merged and released!

/// <summary>
/// Delete a team - must have owner permissions to do this
/// This endpoint route is deprecated and will be removed from the Teams API.
/// We recommend migrating your existing code to use the new Delete a team endpoint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, looking forward to it!

Octokit/Models/Request/UpdateTeam.cs Show resolved Hide resolved
Octokit.Tests/Clients/TeamsClientTests.cs Outdated Show resolved Hide resolved
Octokit/Clients/TeamsClient.cs Outdated Show resolved Hide resolved
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="organization">Org to associate the repo with.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="permission">The permission to grant the team on this repository.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
[ManualRoute("PUT", "/orgs/{org}/team/{team_slug}/repos/{owner}/{repo}")]
[ManualRoute("PUT", "/teams/{team_id}/repos/{owner}/{repo}")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, thanks for explaining! @nickfloyd has mentioned to me that ManualRoute is used for documentation generation rather than implementation, so this makes sense.

/// <returns>The returned <seealso cref="HttpStatusCode"/></returns>
public async Task<HttpStatusCode> Put(Uri uri, string accepts)
public async Task<HttpStatusCode> Put(Uri uri, object body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind explaining why accepts has been removed here? I'm following that you want to PUT the dynamic object similarly to in ApiConnection.cs, but I'm unsure why that means accepts is no longer desirable/needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've double-checked with the current main branch, and this method has only one reference to IConnection.cs.

Since I needed to pass an object, initially I added the object body as an additional parameter. Then I saw that the string accepts is not being passed from anywhere in the codebase, so I decided to remove that argument.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, thank you.

Octokit/Models/Response/Team.cs Outdated Show resolved Hide resolved
Octokit/Models/Response/Team.cs Show resolved Hide resolved
@kfcampbell
Copy link
Member

I'll be 👍 on landing this after a small comment update to link to the REST API docs issue!

@notauserx
Copy link
Contributor Author

@kfcampbell I have added the changes based on your review. Do you think we can get this merged?

Copy link
Member

@kfcampbell kfcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working with me on this change!

@matt-richardson
Copy link
Contributor

🎉 Great to see 🎉. What's the plans around merging and releasing?

@kfcampbell kfcampbell merged commit 891015c into octokit:main Jan 20, 2023
@kfcampbell
Copy link
Member

v5.0.0 has been released with this change in it!

@notauserx notauserx deleted the update-team-permissions-enums branch January 21, 2023 03:33
@notauserx
Copy link
Contributor Author

@kfcampbell thank you for merging my changes.

@@ -71,9 +72,14 @@ public Team(string url, string htmlUrl, int id, string nodeId, string slug, stri
public StringEnum<TeamPrivacy> Privacy { get; private set; }

/// <summary>
/// permission attached to this team
/// Deprecated. The permission that new repositories will be added to the team with when none is specified
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is right. This model is returned from gitHubClient.Repository.GetAllTeams(repositoryOwner, repositoryName), so the permission is actually "what permission does this team have for this repo".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Previously PermissionLevel was wrong too)

Copy link
Contributor Author

@notauserx notauserx Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-richardson you are correct! This comment is more suitable for NewTeam.cs and UpdateTeam.cs than the Team.cs.

From the API reference here, the permission has a description of "Permission that the team will have for its repositories", which I think would be a better comment for this property. I can submit a quick patch updating the comment if we can agree on that.

I am currently working on a PR that takes care of all the other outdated permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Breaking change Used to note any change that requires a major version bump
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Team model uses wrong Permission enum
3 participants