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

Remove package ownerships when removing organization member #1100

Merged
merged 1 commit into from
Jan 5, 2022

Conversation

ericmj
Copy link
Member

@ericmj ericmj commented Jan 4, 2022

This is only a clean up since we always check organization membership when checking package permissions.

To clean up existing membership:

# DELETE
SELECT o.name, p.name, u.username
FROM package_owners AS po
JOIN packages AS p ON po.package_id = p.id
JOIN users AS u ON po.user_id = u.id
JOIN repositories AS r ON p.repository_id = r.id
JOIN organizations AS o ON r.organization_id = o.id
WHERE o.id != 1
  AND o.id NOT IN (SELECT id FROM organization_users WHERE organization_id = o.id);

@sourcelevel-bot
Copy link

SourceLevel has finished reviewing this Pull Request and has found:

  • 1 fixed issue! 🎉

See more details about this review.

Copy link
Member

@supersimple supersimple left a comment

Choose a reason for hiding this comment

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

🌯 💯 🐱

@@ -9,7 +9,7 @@ defmodule Hexpm.ReleaseTasks do
:ecto_sql
]

@repos Application.get_env(:hexpm, :ecto_repos, [])
@repos Application.compile_env(:hexpm, :ecto_repos, [])
Copy link
Member

Choose a reason for hiding this comment

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

I always get confused as to when to use fetch, and when to use compile. Any tips for me?

Copy link
Member

Choose a reason for hiding this comment

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

use compile_env at compile-time 😎 (such as exactly here!)

Copy link
Member

Choose a reason for hiding this comment

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

to expand,

# foo.ex

# this is compile-time
Application.compile_env(:foo, :bar)

defmodule Foo do
  # this is compile-time too
  Application.compile_env(:foo, :bar)

  def foo do
    # this is runtime
    Application.fetch_env(:foo, :bar)

    # inside unquote, we're at compile-time
    unquote(Application.compile_env(:foo, :bar))
  end

  defmacro deffoo do
    # this is compile-time too
    Application.compile_env(:foo, :bar)
    
    quote do
      # this is... it depends how we use the macro. If we use it in module body
      # we'd use compile_env here. If we use the macro inside def, we'd use fetch_env.
    end
  end
end

hope it makes sense and is useful!

@ericmj ericmj merged commit b066e3f into main Jan 5, 2022
@ericmj ericmj deleted the ericmj/remove-package-owners branch January 5, 2022 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants