Feat: add Triage/Maintain permission#2467
Conversation
| /// <summary> | ||
| /// Whether the current user has maintain permissions | ||
| /// </summary> | ||
| public bool Maintain { get; protected set; } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
✅ 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- Get the constructor and a delegate for the constructor
- 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}"); |
There was a problem hiding this comment.
+1 thanks for the simplification here! 🎉
|
Your comment on the convention tests got me interested in how they were setup so I started tinkering a bit, see #2471 👨🔧 |
|
@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? |
|
As I said in #2467 (comment) I’m afraid there is some reflection magic going on somewhere I’m not aware of. |
|
😬 oof, I completely missed that. So sorry. I'll take a look at this first thing tomorrow. |
nickfloyd
left a comment
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
| public bool Admin { get; } | |
| public bool Admin { get; private set; } |
| /// <summary> | ||
| /// Whether the current user has maintain permissions | ||
| /// </summary> | ||
| public bool Maintain { get; } |
There was a problem hiding this comment.
| 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; } |
There was a problem hiding this comment.
| public bool Push { get; } | |
| public bool Push { get; private set; } |
| /// <summary> | ||
| /// Whether the current user has triage permissions | ||
| /// </summary> | ||
| public bool Triage { get; } |
There was a problem hiding this comment.
| 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; } |
There was a problem hiding this comment.
| public bool Pull { get; } | |
| public bool Pull { get; private set; } |
bb87bfc to
94f2391
Compare
|
I made the requested changes + added a test for this convention in 94f2391 |
|
Love it 😍. Thanks 😊 |
|
release_notes: Adds Triage/Maintain permission properties |
Syncs with current state at https://docs.github.com/en/rest/teams/teams#check-team-permissions-for-a-repository
Should fix #2041