Skip to content

Feat: add Triage/Maintain permission#2467

Merged
nickfloyd merged 4 commits intooctokit:mainfrom
janv8000:repository-permissions
Jul 11, 2022
Merged

Feat: add Triage/Maintain permission#2467
nickfloyd merged 4 commits intooctokit:mainfrom
janv8000:repository-permissions

Conversation

@janv8000
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

@nickfloyd nickfloyd left a comment

Choose a reason for hiding this comment

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

Hey @janv8000! Thank you so much for your contributions here! I left a comment on the setter accessors - make the changes if you'd like but it's not a blocker for this changeset.

/// <summary>
/// Whether the current user has maintain permissions
/// </summary>
public bool Maintain { get; protected set; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-Blocker:
Would you mind changing all of these property accessors (on the set) to the more appropriate (given the use case) private? Using protected is currently the dominant pattern in this SDK but given that most of our models now implement ctors in one form or another so that makes it where I think we could change most of the protected access modifiers to the more appropriate private ones.

Let me know your thoughts - I'll be making a push to change all of the model's properties to use the private modifier soon so I am good with whatever you decide. Once done I'll be adding a theory to our model tests to help enforce this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I wasn't sure whether the JSON deserializer in use supported private props.
I made them get-only in 40bdd85 or is that pushing the limits :D

Copy link
Copy Markdown
Contributor

@nickfloyd nickfloyd Jun 30, 2022

Choose a reason for hiding this comment

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

✅ I could go for that... given C# 6 and greater these two are essentially equivalent when it comes to constructors but deviate when it comes to methods internal to the model needing to mutate the properties. I really don’t think there will ever be methods that mutate props on response models; that feels like a code smell - but if there is ever a need we can introduce private again.

Also, I'm not sure how getter-only props shake out with model binding (I think that's more of an ASP.NET Core concern), i.e. [FromBody] and the like. So if we ever choose to go in that direction we can reevaluate the pattern.

I think I like your omitted setter idea better than private for future generated response models. 🎉 Thanks for the thought and effort you put in here! We should be good to merge this.

Copy link
Copy Markdown
Contributor Author

@janv8000 janv8000 Jun 30, 2022

Choose a reason for hiding this comment

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

I'm afraid I've been a bit too zealous.
While debugging this branch in my production code the ctor with the 5 arguments is never hit?

Care to shed some light on the SimpleJsonSerializer internals?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey @janv8000, so I dug into this a bit more. And it looks like you're correct. We need to at minimum implement a setter with the private modifier.

SimpleJson makes heavy use of reflection to:

  1. Get the constructor and a delegate for the constructor
  2. Iterate through a dictionary (created from the incoming payload) and assign values to each given setter

This is why you only see the default constructor getting hit and not the parameter-based one on incoming payloads.

I am making an assumption here, but I believe that the parameterized constructor is primarily used for testing/mocking - because the delegate uses the memoized object map to make the assignments.

Let me know if that makes sense, and apologies again for missing your question the first time around.

get { return string.Format(CultureInfo.InvariantCulture, "Admin: {0}, Push: {1}, Pull: {2}", Admin, Push, Pull); }
get
{
return FormattableString.Invariant($"Admin: {Admin}, Maintain: {Maintain}, Push: {Push}, Triage: {Triage}, Pull: {Pull}");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 thanks for the simplification here! 🎉

@janv8000
Copy link
Copy Markdown
Contributor Author

Your comment on the convention tests got me interested in how they were setup so I started tinkering a bit, see #2471 👨‍🔧

@nickfloyd
Copy link
Copy Markdown
Contributor

@janv8000 I'd like to get this change in for a release tomorrow - are you good with me merging this in or do you want to iterate on it more?

@janv8000
Copy link
Copy Markdown
Contributor Author

As I said in #2467 (comment) I’m afraid there is some reflection magic going on somewhere I’m not aware of.
Are you sure get; suffices for the simplejson serializer or does it really need get; private set; ?

@nickfloyd
Copy link
Copy Markdown
Contributor

😬 oof, I completely missed that. So sorry. I'll take a look at this first thing tomorrow.

Copy link
Copy Markdown
Contributor

@nickfloyd nickfloyd left a comment

Choose a reason for hiding this comment

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

Just added comments on the things that need to change to make this work with the serializer. Let me know your thoughts - i'd be glad to do these as well if you're unable to get to it.

Thanks again for the contributions ❇️

/// Whether the current user has administrative permissions
/// </summary>
public bool Admin { get; protected set; }
public bool Admin { get; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public bool Admin { get; }
public bool Admin { get; private set; }

/// <summary>
/// Whether the current user has maintain permissions
/// </summary>
public bool Maintain { get; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public bool Maintain { get; }
public bool Maintain { get; private set; }

/// Whether the current user has push permissions
/// </summary>
public bool Push { get; protected set; }
public bool Push { get; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public bool Push { get; }
public bool Push { get; private set; }

/// <summary>
/// Whether the current user has triage permissions
/// </summary>
public bool Triage { get; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public bool Triage { get; }
public bool Triage { get; private set; }

/// Whether the current user has pull permissions
/// </summary>
public bool Pull { get; protected set; }
public bool Pull { get; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
public bool Pull { get; }
public bool Pull { get; private set; }

janv8000 added a commit to janv8000/octokit.net that referenced this pull request Jul 4, 2022
@janv8000 janv8000 force-pushed the repository-permissions branch from bb87bfc to 94f2391 Compare July 4, 2022 09:09
@janv8000 janv8000 changed the title [WIP] feat: add Triage/Maintain permission Feat: add Triage/Maintain permission Jul 4, 2022
@janv8000
Copy link
Copy Markdown
Contributor Author

janv8000 commented Jul 4, 2022

I made the requested changes + added a test for this convention in 94f2391

@nickfloyd nickfloyd self-requested a review July 7, 2022 19:32
@nickfloyd nickfloyd merged commit f92f0b8 into octokit:main Jul 11, 2022
@terrajobst
Copy link
Copy Markdown

Love it 😍. Thanks 😊

@nickfloyd
Copy link
Copy Markdown
Contributor

release_notes: Adds Triage/Maintain permission properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose triage and maintain permissions

4 participants