Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
compendium-v2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
compendium-v2
Commits
2c6e3edc
Commit
2c6e3edc
authored
2 years ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
Add user model and annotation future imports
parent
c4c9b0b3
No related branches found
No related tags found
1 merge request
!44
Feature/comp 208 google o auth poc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
compendium_v2/db/auth_model.py
+72
-0
72 additions, 0 deletions
compendium_v2/db/auth_model.py
compendium_v2/db/model.py
+3
-0
3 additions, 0 deletions
compendium_v2/db/model.py
compendium_v2/db/survey_model.py
+3
-0
3 additions, 0 deletions
compendium_v2/db/survey_model.py
with
78 additions
and
0 deletions
compendium_v2/db/auth_model.py
0 → 100644
+
72
−
0
View file @
2c6e3edc
# annotations import is required for sqlalchemy annotations to work properly
from
__future__
import
annotations
import
logging
from
datetime
import
datetime
from
enum
import
Enum
from
uuid
import
UUID
,
uuid4
from
typing_extensions
import
Annotated
from
sqlalchemy
import
Table
,
Column
from
sqlalchemy.orm
import
Mapped
,
mapped_column
,
relationship
from
sqlalchemy.schema
import
ForeignKey
from
flask_login
import
UserMixin
# type: ignore
from
compendium_v2.db
import
db
from
compendium_v2.db.model
import
NREN
logger
=
logging
.
getLogger
(
__name__
)
class
ROLES
(
Enum
):
admin
=
"
admin
"
user
=
"
user
"
uuid_pk
=
Annotated
[
UUID
,
mapped_column
(
primary_key
=
True
,
default
=
lambda
_
:
str
(
uuid4
()))]
int_pk_fkNREN
=
Annotated
[
int
,
mapped_column
(
ForeignKey
(
"
nren.id
"
),
primary_key
=
True
)]
# TODO: active should be default False and require admin approval
# (ROLES.admin) when there is a way to handle this in a GUI
active
=
Annotated
[
bool
,
mapped_column
(
db
.
Boolean
,
default
=
True
)]
roles
=
Annotated
[
ROLES
,
mapped_column
(
db
.
Enum
(
ROLES
),
default
=
ROLES
.
user
)]
# annotations for many-to-many relationships
user_id
=
Annotated
[
UUID
,
mapped_column
(
ForeignKey
(
"
user.id
"
),
primary_key
=
True
)]
nren_id
=
Annotated
[
int
,
mapped_column
(
ForeignKey
(
"
nren.id
"
),
primary_key
=
True
)]
_datetime
=
Annotated
[
datetime
,
mapped_column
(
db
.
DateTime
,
default
=
datetime
.
utcnow
)]
UserNrenMember
=
Table
(
"
user_nren_member
"
,
db
.
Model
.
metadata
,
Column
(
"
user_id
"
,
ForeignKey
(
"
user.id
"
)),
Column
(
"
nren_id
"
,
ForeignKey
(
"
nren.id
"
)),
)
# Unfortunately flask-sqlalchemy doesnt fully support DeclarativeBase yet.
# See https://github.com/pallets-eco/flask-sqlalchemy/issues/1140
# mypy: disable-error-code="name-defined"
class
User
(
UserMixin
,
db
.
Model
):
__tablename__
=
'
user
'
id
:
Mapped
[
uuid_pk
]
active
:
Mapped
[
active
]
roles
:
Mapped
[
roles
]
email
:
Mapped
[
str
]
fullname
:
Mapped
[
str
]
oidc_sub
:
Mapped
[
str
]
# ID from OIDC provider
created_at
:
Mapped
[
_datetime
]
last_login
:
Mapped
[
_datetime
]
nrens
:
Mapped
[
NREN
]
=
relationship
(
secondary
=
UserNrenMember
,
lazy
=
'
joined
'
)
def
__repr__
(
self
):
return
'
<User %r>
'
%
self
.
email
@property
def
is_active
(
self
):
return
self
.
active
This diff is collapsed.
Click to expand it.
compendium_v2/db/model.py
+
3
−
0
View file @
2c6e3edc
# annotations import is required for sqlalchemy annotations to work properly
from
__future__
import
annotations
import
logging
import
logging
from
decimal
import
Decimal
from
decimal
import
Decimal
from
enum
import
Enum
from
enum
import
Enum
...
...
This diff is collapsed.
Click to expand it.
compendium_v2/db/survey_model.py
+
3
−
0
View file @
2c6e3edc
# annotations import is required for sqlalchemy annotations to work properly
from
__future__
import
annotations
import
logging
import
logging
from
typing
import
Dict
,
Any
from
typing
import
Dict
,
Any
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment