-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
353 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
administration/src/bp-modules/user-settings/UserUploadApiTokenSettings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import { Button, H2, H4, HTMLSelect, HTMLTable } from '@blueprintjs/core' | ||
import Delete from '@mui/icons-material/Delete' | ||
import React, { useEffect, useState } from 'react' | ||
import styled from 'styled-components' | ||
|
||
import getMessageFromApolloError from '../../errors/getMessageFromApolloError' | ||
import { | ||
UserUploadApiTokenMetaData, | ||
useCreateUserUploadApiTokenMutation, | ||
useDeleteUserUploadApiTokenMutation, | ||
useGetUserUploadApiTokenMetaDataQuery, | ||
} from '../../generated/graphql' | ||
import { formatDate } from '../../util/formatDate' | ||
import { useAppToaster } from '../AppToaster' | ||
import getQueryResult from '../util/getQueryResult' | ||
import SettingsCard from './SettingsCard' | ||
|
||
const Container = styled.div` | ||
background: ghostwhite; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05); | ||
` | ||
|
||
const Row = styled.div` | ||
width: 80%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-bottom: 15px; | ||
` | ||
|
||
const NewTokenText = styled.p` | ||
font-size: 18px; | ||
color: #007bff; | ||
background: #e9f7ff; | ||
padding: 10px; | ||
border-radius: 6px; | ||
margin-top: 15px; | ||
word-break: break-all; | ||
` | ||
|
||
const UserUploadApiTokenSetting = () => { | ||
const metaDataQuery = useGetUserUploadApiTokenMetaDataQuery({}) | ||
|
||
const appToaster = useAppToaster() | ||
|
||
const [tokenMetaData, setTokenMetadata] = useState<Array<UserUploadApiTokenMetaData>>([]) | ||
const [createdToken, setCreatedToken] = useState<string>('') | ||
const [expiresIn, setExpiresIn] = useState<number>(1) | ||
|
||
useEffect(() => { | ||
const metaDataQueryResult = getQueryResult(metaDataQuery) | ||
if (metaDataQueryResult.successful) { | ||
const { tokenMetaData } = metaDataQueryResult.data | ||
setTokenMetadata(tokenMetaData) | ||
} | ||
}, [metaDataQuery, tokenMetaData]) | ||
|
||
const [createToken] = useCreateUserUploadApiTokenMutation({ | ||
onCompleted: result => { | ||
appToaster?.show({ intent: 'success', message: 'Token wurde erfolgreich erzeugt.' }) | ||
setCreatedToken(result.createUserUploadApiTokenPayload) | ||
metaDataQuery.refetch() | ||
}, | ||
onError: error => { | ||
const { title } = getMessageFromApolloError(error) | ||
appToaster?.show({ | ||
intent: 'danger', | ||
message: title, | ||
}) | ||
}, | ||
}) | ||
|
||
const [deleteToken] = useDeleteUserUploadApiTokenMutation({ | ||
onCompleted: result => { | ||
appToaster?.show({ intent: 'success', message: 'Token wurde erfolgreich gelöscht.' }) | ||
metaDataQuery.refetch() | ||
}, | ||
onError: error => { | ||
const { title } = getMessageFromApolloError(error) | ||
appToaster?.show({ | ||
intent: 'danger', | ||
message: title, | ||
}) | ||
}, | ||
}) | ||
|
||
return ( | ||
<SettingsCard> | ||
<H2>Api Token</H2> | ||
|
||
<Container> | ||
<H4>Neues Token erstellen</H4> | ||
<p>Ein neu erzeugtes Token wir nur einmalig angezeigt und kann danach nicht wieder abgerufen werden.</p> | ||
<Row> | ||
<label htmlFor='expiresIn'>Gültigkeitsdauer:</label> | ||
<HTMLSelect | ||
name='expiresIn' | ||
id='expiresIn' | ||
value={expiresIn} | ||
onChange={e => setExpiresIn(parseInt(e.target.value))}> | ||
<option value='1'>1 Monat</option> | ||
<option value='3'>3 Monate</option> | ||
<option value='12'>1 Jahr</option> | ||
<option value='36'>3 Jahre</option> | ||
</HTMLSelect> | ||
|
||
<Button intent='primary' onClick={() => createToken({ variables: { expiresIn: expiresIn } })}> | ||
Erstellen | ||
</Button> | ||
</Row> | ||
{createdToken && <NewTokenText>New Token: {createdToken}</NewTokenText>} | ||
</Container> | ||
|
||
{tokenMetaData.length > 0 && ( | ||
<HTMLTable> | ||
<thead> | ||
<tr> | ||
<th>E-Mail des Erstellers</th> | ||
<th>Ablaufdatum</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{tokenMetaData.map((item, index) => ( | ||
<tr key={index}> | ||
<td>{item.creatorEmail}</td> | ||
<td>{formatDate(item.expirationDate)}</td> | ||
<td> | ||
<Delete color='error' onClick={() => deleteToken({ variables: { id: item.id } })} /> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</HTMLTable> | ||
)} | ||
</SettingsCard> | ||
) | ||
} | ||
|
||
export default UserUploadApiTokenSetting |
3 changes: 3 additions & 0 deletions
3
administration/src/graphql/auth/createUserUploadApiToken.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation createUserUploadApiToken($expiresIn: Int!) { | ||
createUserUploadApiTokenPayload: createUserUploadApiToken(expiresIn: $expiresIn) | ||
} |
3 changes: 3 additions & 0 deletions
3
administration/src/graphql/auth/deleteUserUploadApiToken.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation deleteUserUploadApiToken($id: Int!) { | ||
deleteUserUploadApiToken(id: $id) | ||
} |
7 changes: 7 additions & 0 deletions
7
administration/src/graphql/auth/getUserUploadApiTokensMetaData.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
query getUserUploadApiTokenMetaData { | ||
tokenMetaData: getUserUploadApiTokenMetaData { | ||
id | ||
creatorEmail | ||
expirationDate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ const config: ProjectConfig = { | |
storeManagement: { | ||
enabled: false, | ||
}, | ||
apiUpload: false, | ||
} | ||
|
||
export default config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...in/kotlin/app/ehrenamtskarte/backend/auth/database/repos/UserUploadApiTokensRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app.ehrenamtskarte.backend.auth.database.repos | ||
|
||
import app.ehrenamtskarte.backend.auth.database.UserUploadApiTokenEntity | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import java.time.LocalDate | ||
|
||
object UserUploadApiTokensRepository { | ||
fun insert( | ||
token: ByteArray, | ||
adminId: EntityID<Int>, | ||
expirationDate: LocalDate, | ||
projectId: EntityID<Int> | ||
): UserUploadApiTokenEntity { | ||
return UserUploadApiTokenEntity.new { | ||
this.token = token | ||
this.creator = adminId | ||
this.expirationDate = expirationDate | ||
this.projectId = projectId | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.