Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Kort
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Onboarding
AlekSIS-App-Kort
Commits
16d25841
Verified
Commit
16d25841
authored
3 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Integrate OAuth2 with printer management
parent
dbb11feb
No related branches found
No related tags found
No related merge requests found
Pipeline
#59022
failed
3 years ago
Stage: prepare
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
aleksis/apps/kort/apps.py
+24
-0
24 additions, 0 deletions
aleksis/apps/kort/apps.py
aleksis/apps/kort/migrations/0006_auto_20220310_2003.py
+32
-0
32 additions, 0 deletions
aleksis/apps/kort/migrations/0006_auto_20220310_2003.py
aleksis/apps/kort/models.py
+28
-3
28 additions, 3 deletions
aleksis/apps/kort/models.py
with
84 additions
and
3 deletions
aleksis/apps/kort/apps.py
+
24
−
0
View file @
16d25841
from
django.apps
import
apps
from
django.db
import
models
from
django.db.models
import
functions
from
django.utils.translation
import
gettext
as
_
from
aleksis.core.util.apps
import
AppConfig
...
...
@@ -16,3 +21,22 @@ class DefaultConfig(AppConfig):
"
Jonathan Weth
"
,
"
dev@jonathanweth.de
"
,
)
@classmethod
def
get_all_scopes
(
cls
)
->
dict
[
str
,
str
]:
"""
Return all OAuth scopes and their descriptions for this app.
"""
Card
=
apps
.
get_model
(
"
kort
"
,
"
Card
"
)
label_prefix
=
_
(
"
Access and manage printer status and print jobs
"
)
scopes
=
dict
(
Card
.
objects
.
annotate
(
scope
=
functions
.
Concat
(
models
.
Value
(
f
"
{
Card
.
SCOPE_PREFIX
}
_
"
),
models
.
F
(
"
pk
"
),
output_field
=
models
.
CharField
(),
),
label
=
functions
.
Concat
(
models
.
Value
(
f
"
{
label_prefix
}
:
"
),
models
.
F
(
"
name
"
)),
)
.
values_list
(
"
scope
"
,
"
label
"
)
.
distinct
()
)
return
scopes
This diff is collapsed.
Click to expand it.
aleksis/apps/kort/migrations/0006_auto_20220310_2003.py
0 → 100644
+
32
−
0
View file @
16d25841
# Generated by Django 3.2.12 on 2022-03-10 19:03
from
django.conf
import
settings
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
migrations
.
swappable_dependency
(
settings
.
OAUTH2_PROVIDER_APPLICATION_MODEL
),
(
'
kort
'
,
'
0005_card_pdf_file
'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'
cardprinter
'
,
name
=
'
oauth2_application
'
,
field
=
models
.
ForeignKey
(
default
=
0
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'
core.oauthapplication
'
,
verbose_name
=
'
OAuth2 application
'
),
preserve_default
=
False
,
),
migrations
.
AlterField
(
model_name
=
'
cardprinter
'
,
name
=
'
location
'
,
field
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
verbose_name
=
'
Location
'
),
),
migrations
.
AlterField
(
model_name
=
'
cardprinter
'
,
name
=
'
status
'
,
field
=
models
.
CharField
(
choices
=
[(
'
online
'
,
'
Online
'
),
(
'
offline
'
,
'
Offline
'
),
(
'
with_errors
'
,
'
With errors
'
),
(
'
not_registered
'
,
'
Not registered
'
)],
default
=
'
not_registered
'
,
max_length
=
255
,
verbose_name
=
'
Status
'
),
),
]
This diff is collapsed.
Click to expand it.
aleksis/apps/kort/models.py
+
28
−
3
View file @
16d25841
...
...
@@ -10,13 +10,14 @@ from django.utils.translation import gettext as _
from
celery.result
import
AsyncResult
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.models
import
Person
from
aleksis.core.models
import
OAuthApplication
,
Person
class
CardPrinterStatus
(
models
.
TextChoices
):
ONLINE
=
"
online
"
,
_
(
"
Online
"
)
OFFLINE
=
"
offline
"
,
_
(
"
Offline
"
)
WITH_ERRORS
=
"
with_errors
"
,
_
(
"
With errors
"
)
NOT_REGISTERED
=
"
not_registered
"
,
_
(
"
Not registered
"
)
class
PrintStatus
(
models
.
TextChoices
):
...
...
@@ -26,16 +27,40 @@ class PrintStatus(models.TextChoices):
class
CardPrinter
(
ExtensibleModel
):
SCOPE_PREFIX
=
"
card_printer
"
name
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Name
"
))
description
=
models
.
TextField
(
verbose_name
=
_
(
"
Description
"
),
blank
=
True
)
location
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Location
"
))
location
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Location
"
)
,
blank
=
True
)
status
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Status
"
),
choices
=
CardPrinterStatus
.
choices
max_length
=
255
,
verbose_name
=
_
(
"
Status
"
),
choices
=
CardPrinterStatus
.
choices
,
default
=
CardPrinterStatus
.
NOT_REGISTERED
,
)
status_text
=
models
.
TextField
(
verbose_name
=
_
(
"
Status text
"
),
blank
=
True
)
last_seen_at
=
models
.
DateTimeField
(
verbose_name
=
_
(
"
Last seen at
"
),
blank
=
True
,
null
=
True
)
oauth2_application
=
models
.
ForeignKey
(
to
=
OAuthApplication
,
on_delete
=
models
.
CASCADE
,
verbose_name
=
_
(
"
OAuth2 application
"
),
blank
=
True
,
null
=
True
,
)
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
oauth2_application
:
application
=
OAuthApplication
(
client_type
=
OAuthApplication
.
CLIENT_CONFIDENTIAL
,
authorization_grant_type
=
OAuthApplication
.
GRANT_AUTHORIZATION_CODE
,
name
=
f
"
Card printer:
{
self
.
name
}
"
,
)
application
.
save
()
self
.
oauth2_application
=
application
super
().
save
(
*
args
,
**
kwargs
)
def
__str__
(
self
):
return
self
.
name
...
...
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