Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Digitaler 3G-Nachweis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
AStA
Digitaler 3G-Nachweis
Commits
1d834abe
Commit
1d834abe
authored
3 years ago
by
Leon Tappe
Browse files
Options
Downloads
Patches
Plain Diff
add settings backend
parent
c29b87d0
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
backend/website/models.py
+6
-0
6 additions, 0 deletions
backend/website/models.py
backend/website/routes.py
+51
-1
51 additions, 1 deletion
backend/website/routes.py
with
57 additions
and
1 deletion
backend/website/models.py
+
6
−
0
View file @
1d834abe
...
...
@@ -58,6 +58,12 @@ class Color(db.Model):
name
=
db
.
Column
(
db
.
String
(
50
),
unique
=
False
)
class
Setting
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
key
=
db
.
Column
(
db
.
String
(
50
),
unique
=
True
)
value
=
db
.
Column
(
db
.
String
(
50
),
unique
=
False
)
class
OAuth2Client
(
db
.
Model
,
OAuth2ClientMixin
):
__tablename__
=
'
oauth2_client
'
...
...
This diff is collapsed.
Click to expand it.
backend/website/routes.py
+
51
−
1
View file @
1d834abe
...
...
@@ -8,7 +8,7 @@ from dateutil.tz import tzutc, gettz
from
dateutil
import
parser
,
utils
from
time
import
time
from
.oauth2
import
authorization
,
require_oauth
,
OAuth2Client
from
.models
import
AccessCode
,
Color
,
ColorAllocation
,
OAuth2AuthorizationCode
,
OAuth2Token
,
db
,
User
from
.models
import
AccessCode
,
Color
,
ColorAllocation
,
OAuth2AuthorizationCode
,
OAuth2Token
,
db
,
User
,
Setting
from
authlib.oauth2
import
OAuth2Error
from
authlib.integrations.flask_oauth2
import
current_token
import
base64
...
...
@@ -566,3 +566,53 @@ def current_color():
if
(
alloc
==
None
):
return
'
no color found for today
'
,
404
return
jsonify
(
color
=
alloc
.
color
.
hex
,
inverse
=
alloc
.
color
.
inverse
)
def
get_settings
():
settings
=
Setting
.
query
.
all
()
settings_map
=
[]
for
setting
in
settings
:
settings_map
.
append
({
'
key
'
:
setting
.
key
,
'
value
'
:
setting
.
value
})
return
jsonify
(
settings_map
)
@bp.route
(
'
/admin/settings
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@require_oauth
(
'
admin
'
)
def
admin_settings
():
if
request
.
method
==
'
GET
'
:
return
get_settings
()
if
request
.
method
==
'
POST
'
:
setting
=
Setting
(
day
=
request
.
json
[
'
key
'
],
color_id
=
request
.
json
[
'
value
'
])
try
:
db
.
session
.
add
(
setting
)
db
.
session
.
commit
()
new_setting
=
Setting
.
query
.
filter_by
(
key
=
setting
.
key
).
first
()
return
jsonify
({
'
key
'
:
new_setting
.
key
,
'
value
'
:
new_setting
.
value
})
except
:
return
'
failed to add setting, check for duplicate key
'
,
400
@bp.route
(
'
/admin/settings/<string:key>
'
,
methods
=
[
'
GET
'
,
'
PUT
'
,
'
DELETE
'
])
@require_oauth
(
'
admin
'
)
def
single_setting
(
key
):
if
request
.
method
==
'
GET
'
:
setting
=
Setting
.
query
.
filter_by
(
key
=
key
).
first
()
return
jsonify
({
'
key
'
:
setting
.
key
,
'
value
'
:
setting
.
value
})
if
request
.
method
==
'
PUT
'
:
if
db
.
session
.
query
(
Setting
).
filter
(
Setting
.
key
==
key
).
update
({
Setting
.
value
:
request
.
json
[
'
value
'
]})
<
1
:
return
'
not found
'
,
404
db
.
session
.
commit
()
new_setting
=
Setting
.
query
.
filter_by
(
key
=
key
).
first
()
return
jsonify
({
'
key
'
:
new_setting
.
key
,
'
value
'
:
new_setting
.
value
})
if
request
.
method
==
'
DELETE
'
:
if
db
.
session
.
query
(
Setting
).
filter
(
Setting
.
key
==
key
).
delete
()
<
1
:
return
'
not found
'
,
404
db
.
session
.
commit
()
return
'
success
'
,
200
@bp.route
(
'
/settings
'
,
methods
=
[
'
GET
'
])
@require_oauth
(
'
user
'
)
def
user_settings
():
return
get_settings
()
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