-
Notifications
You must be signed in to change notification settings - Fork 11
Add user to orgs by default #371
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,11 +56,13 @@ def sign_in_user(user_name, password): | |
| } | ||
| user_roles.append(temp_dict) | ||
| else: | ||
| # XXX: Roles is [] || [""] || [{}]? | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forget the exact reason why its set like this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries! Little breadcrumbs leading us back to things to simplify. |
||
| # why not just []? | ||
| user_roles = ["none"] | ||
| try: | ||
| payload = { | ||
| "exp": datetime.datetime.utcnow() | ||
| + datetime.timedelta(days=0, seconds=1800), | ||
| + datetime.timedelta(days=0, seconds=1800), # XXX: too short | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When this was initially created Po approved the 30min time limit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha! We'll have to figure that out. I was finding that was so short that it was actually invalidating my jwts while I was debugging stuff!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I know that feeling 😂 |
||
| "iat": datetime.datetime.utcnow(), | ||
| "user_id": user.id, | ||
| "roles": user_roles, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| """empty message | ||
|
|
||
| Revision ID: b781fb62a115 | ||
| Revises: 1860746a39e4 | ||
| Create Date: 2020-05-06 13:19:46.906351 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "b781fb62a115" | ||
| down_revision = "1860746a39e4" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.add_column("organizations", sa.Column("name", sa.String(), nullable=True)) | ||
| op.add_column("organizations", sa.Column("slug", sa.String(), nullable=True)) | ||
| op.create_index( | ||
| op.f("ix_organizations_slug"), "organizations", ["slug"], unique=False | ||
| ) | ||
| op.drop_constraint("user_user_aff_key", "user_affiliations", type_="foreignkey") | ||
| op.drop_constraint( | ||
| "user_affiliations_organization_id_fkey", | ||
| "user_affiliations", | ||
| type_="foreignkey", | ||
| ) | ||
| op.create_foreign_key( | ||
| "user_affiliations_organization_id_fkey", | ||
| "user_affiliations", | ||
| "organizations", | ||
| ["organization_id"], | ||
| ["id"], | ||
| onupdate="CASCADE", | ||
| ondelete="CASCADE", | ||
| ) | ||
| op.create_foreign_key( | ||
| "user_affiliations_users_id_fkey", | ||
| "user_affiliations", | ||
| "users", | ||
| ["user_id"], | ||
| ["id"], | ||
| onupdate="CASCADE", | ||
| ondelete="CASCADE", | ||
| ) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_constraint( | ||
| "user_affiliations_users_id_fkey", "user_affiliations", type_="foreignkey" | ||
| ) | ||
| op.drop_constraint( | ||
| "user_affiliations_organization_id_fkey", | ||
| "user_affiliations", | ||
| type_="foreignkey", | ||
| ) | ||
| op.create_foreign_key( | ||
| "user_affiliations_organization_id_fkey", | ||
| "user_affiliations", | ||
| "organizations", | ||
| ["organization_id"], | ||
| ["id"], | ||
| ) | ||
| op.create_foreign_key( | ||
| "user_user_aff_key", "user_affiliations", "users", ["user_id"], ["id"] | ||
| ) | ||
| op.drop_index(op.f("ix_organizations_slug"), table_name="organizations") | ||
| op.drop_column("organizations", "slug") | ||
| op.drop_column("organizations", "name") | ||
| # ### end Alembic commands ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| """empty message | ||
|
|
||
| Revision ID: 1860746a39e4 | ||
| Revises: cf42b66dbc12 | ||
| Create Date: 2020-04-30 22:30:22.681303 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy.schema import Sequence, CreateSequence | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "1860746a39e4" | ||
| down_revision = "cf42b66dbc12" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.execute(CreateSequence(Sequence("dmarc_reports_id_seq"))) | ||
| op.execute( | ||
| "ALTER TABLE dmarc_reports ALTER COLUMN id SET DEFAULT nextval('public.dmarc_reports_id_seq')" | ||
| ) | ||
| op.execute("ALTER SEQUENCE dmarc_reports_id_seq OWNED BY dmarc_reports.id") | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.execute("ALTER TABLE dmarc_reports ALTER COLUMN id DROP DEFAULT") | ||
| op.execute("DROP SEQUENCE dmarc_reports_id_seq") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
user_idis being pulled from the jwt, and the reason why there is another query touser_affiliationsis to confirm that the users access is up to date and has not been modified since initial loginThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we did a joinedload and loaded both the user and their affiliations in one shot at the beginning of the request that would be good. But I guess you're getting at the idea that another thread/query could change the state in the db between that inital load and when this gets executed. I'll have to think about that.