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
6d28b4ff
Verified
Commit
6d28b4ff
authored
1 year ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Fix models to work correctly with client secrets
(cherry picked from commit
3a9e8fb9
)
parent
9d78e1a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/kort/migrations/0016_cardprinter_oauth2_client_secret.py
+2
-2
2 additions, 2 deletions
.../kort/migrations/0016_cardprinter_oauth2_client_secret.py
aleksis/apps/kort/models.py
+19
-4
19 additions, 4 deletions
aleksis/apps/kort/models.py
with
21 additions
and
6 deletions
aleksis/apps/kort/migrations/001
7
_cardprinter_oauth2_client_secret.py
→
aleksis/apps/kort/migrations/001
6
_cardprinter_oauth2_client_secret.py
+
2
−
2
View file @
6d28b4ff
# Generated by Django 4.
1.9
on 2023-0
6-17 18:42
# Generated by Django 4.
2.4
on 2023-0
8-30 14:25
from
django.db
import
migrations
,
models
from
django.db
import
migrations
,
models
import
django.db.models.deletion
import
django.db.models.deletion
...
@@ -8,7 +8,7 @@ class Migration(migrations.Migration):
...
@@ -8,7 +8,7 @@ class Migration(migrations.Migration):
dependencies
=
[
dependencies
=
[
(
"
sites
"
,
"
0002_alter_domain_unique
"
),
(
"
sites
"
,
"
0002_alter_domain_unique
"
),
(
"
kort
"
,
"
001
6_card_last_read_counter
"
),
(
"
kort
"
,
"
001
5_migrate_scopes
"
),
]
]
operations
=
[
operations
=
[
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/kort/models.py
+
19
−
4
View file @
6d28b4ff
...
@@ -14,6 +14,7 @@ from django.utils.translation import gettext as _
...
@@ -14,6 +14,7 @@ from django.utils.translation import gettext as _
from
celery.result
import
AsyncResult
from
celery.result
import
AsyncResult
from
model_utils.models
import
TimeStampedModel
from
model_utils.models
import
TimeStampedModel
from
oauth2_provider.generators
import
generate_client_secret
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.mixins
import
ExtensibleModel
from
aleksis.core.models
import
OAuthApplication
,
Person
from
aleksis.core.models
import
OAuthApplication
,
Person
...
@@ -82,27 +83,41 @@ class CardPrinter(ExtensibleModel):
...
@@ -82,27 +83,41 @@ class CardPrinter(ExtensibleModel):
null
=
True
,
null
=
True
,
related_name
=
"
card_printers
"
,
related_name
=
"
card_printers
"
,
)
)
oauth2_client_secret
=
models
.
CharField
(
max_length
=
255
,
blank
=
True
,
verbose_name
=
_
(
"
OAuth2 client secret
"
),
)
# Settings
# Settings
cups_printer
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
CUPS printer
"
),
blank
=
True
)
cups_printer
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
CUPS printer
"
),
blank
=
True
,
help_text
=
_
(
"
Leave blank to deactivate CUPS printing
"
),
)
generate_number_on_server
=
models
.
BooleanField
(
generate_number_on_server
=
models
.
BooleanField
(
default
=
True
,
verbose_name
=
_
(
"
Generate card number on server
"
)
default
=
True
,
verbose_name
=
_
(
"
Generate card number on server
"
)
)
)
card_detector
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Card detector
"
),
blank
=
True
)
card_detector
=
models
.
CharField
(
max_length
=
255
,
verbose_name
=
_
(
"
Card detector
"
),
blank
=
True
)
def
save
(
self
,
*
args
,
**
kwargs
):
def
save
(
self
,
*
args
,
**
kwargs
):
super
().
save
(
*
args
,
**
kwargs
)
if
not
self
.
oauth2_application
:
if
not
self
.
oauth2_application
:
client_secret
=
generate_client_secret
()
application
=
OAuthApplication
(
application
=
OAuthApplication
(
client_type
=
OAuthApplication
.
CLIENT_CONFIDENTIAL
,
client_type
=
OAuthApplication
.
CLIENT_CONFIDENTIAL
,
authorization_grant_type
=
OAuthApplication
.
GRANT_CLIENT_CREDENTIALS
,
authorization_grant_type
=
OAuthApplication
.
GRANT_CLIENT_CREDENTIALS
,
name
=
f
"
Card printer:
{
self
.
name
}
"
,
name
=
f
"
Card printer:
{
self
.
name
}
"
,
redirect_uris
=
"
urn:ietf:wg:oauth:2.0:oob
"
,
allowed_scopes
=
[
self
.
scope
],
allowed_scopes
=
[
self
.
scope
],
client_secret
=
client_secret
,
)
)
application
.
save
()
application
.
save
()
self
.
oauth2_application
=
application
self
.
oauth2_application
=
application
self
.
oauth2_client_secret
=
client_secret
super
().
save
(
*
args
,
**
kwargs
)
super
().
save
(
*
args
,
**
kwargs
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
name
return
self
.
name
...
@@ -127,7 +142,7 @@ class CardPrinter(ExtensibleModel):
...
@@ -127,7 +142,7 @@ class CardPrinter(ExtensibleModel):
config
=
{
config
=
{
"
base_url
"
:
settings
.
BASE_URL
,
"
base_url
"
:
settings
.
BASE_URL
,
"
client_id
"
:
self
.
oauth2_application
.
client_id
,
"
client_id
"
:
self
.
oauth2_application
.
client_id
,
"
client_secret
"
:
self
.
oauth2_
application
.
client_secret
,
"
client_secret
"
:
self
.
oauth2_client_secret
,
}
}
return
config
return
config
...
...
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