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

Use middleware to load org #4208

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

6543
Copy link
Member

@6543 6543 commented Oct 7, 2024

close #4207

@woodpecker-bot
Copy link
Collaborator

Deploying preview to https://woodpecker-ci-woodpecker-pr-4208.surge.sh

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 93 lines in your changes missing coverage. Please review.

Project coverage is 26.52%. Comparing base (ddd55ee) to head (ecae628).

Files with missing lines Patch % Lines
server/router/middleware/session/org.go 0.00% 38 Missing ⚠️
server/api/org_registry.go 0.00% 19 Missing ⚠️
server/api/org_secret.go 0.00% 19 Missing ⚠️
server/api/agent.go 0.00% 6 Missing ⚠️
server/api/org.go 0.00% 5 Missing ⚠️
server/router/middleware/session/user.go 0.00% 4 Missing ⚠️
server/router/api.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4208      +/-   ##
==========================================
+ Coverage   26.47%   26.52%   +0.05%     
==========================================
  Files         376      377       +1     
  Lines       27465    27426      -39     
==========================================
+ Hits         7270     7275       +5     
+ Misses      19530    19486      -44     
  Partials      665      665              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@anbraten anbraten changed the title Create middleware to load org and use it Use middleware to load org Oct 8, 2024
server/router/middleware/session/user.go Outdated Show resolved Hide resolved
server/router/middleware/session/org.go Outdated Show resolved Hide resolved
@6543 6543 requested a review from anbraten October 8, 2024 18:40
)

func Org(c *gin.Context) *model.Org {
v, ok := c.Get("org")
Copy link
Member

@anbraten anbraten Oct 8, 2024

Choose a reason for hiding this comment

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

This one only works now if MustOrg was called previously?!

Copy link
Member Author

Choose a reason for hiding this comment

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

yes as with other middleware ...

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a feature not a bug ... I understand that it could be frigned if you just read the functions behind endpints ... but we do the dame to ensure permissions are set and respected etc ...

... this decuples the endpoint function a bit and also allow tests to be more easy to write agains it ...

Copy link
Member

@anbraten anbraten Oct 9, 2024

Choose a reason for hiding this comment

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

but we do the dame to ensure permissions are set and respected etc ...

Actually not, we always call SetUser, SetPerm, SetRepo as in https://github.com/anbraten/woodpecker/blob/46f4c589421a790f98ff9759d230b6428b6312e8/server/router/api.go#L91-L92 in the router to add sth to the context and later on, load it using MustUser or User.

Should I push the change to show you what I mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor delete or replace old code server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: create middleware which set the org for the apis dedicated to orgs
3 participants