Skip to content

Commit

Permalink
Merge pull request #48 from icefoganalytics/issue-25/build-datasets-t…
Browse files Browse the repository at this point in the history
…able-request-access-button-action

Build Datasets Table Request Access And Subscribe Buttons Actions
  • Loading branch information
klondikemarlen authored Feb 21, 2024
2 parents 930051c + bde2112 commit d16bcfd
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { faker } from "@faker-js/faker"
import { CreationAttributes } from "sequelize"

import { Dataset, AccessGrant } from "@/models"
import { Dataset, AccessGrant, AccessRequest } from "@/models"
import { AccessTypes, GrantLevels } from "@/models/access-grant"

import BaseController from "@/controllers/base-controller"

const AVAILABLE_ACCESS_TYPES = [
AccessTypes.OPEN_ACCESS,
AccessTypes.SELF_SERVE_ACCESS,
AccessTypes.SCREENED_ACCESS,
]

export class ApplyRandomAccessGrantsController extends BaseController {
async create() {
try {
await AccessRequest.destroy({ where: {}, force: true })
await AccessGrant.destroy({ where: {}, force: true })
await this.applyRandomAccessGrantsToDatasets()
return this.response
Expand Down Expand Up @@ -36,7 +43,7 @@ export class ApplyRandomAccessGrantsController extends BaseController {
creatorId: dataset.ownerId,
// TODO: supportId: faker.helpers.arrayElement(users - dataset.owner).id,
grantLevel: randomGrantLevel,
accessType: faker.helpers.arrayElement(Object.values(AccessTypes)),
accessType: faker.helpers.arrayElement(AVAILABLE_ACCESS_TYPES),
isProjectDescriptionRequired: faker.datatype.boolean(),
})
)
Expand Down
1 change: 1 addition & 0 deletions api/src/middlewares/authorization-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type AuthorizationRequest = JwtRequest & {
async function findOrCreateUserFromAuth0Token(token: string): Promise<User> {
const { auth0Subject, email, firstName, lastName } = await auth0Integration.getUserInfo(token)

// TODO: move to ensure user service
const [user, created] = await User.findOrCreate({
where: { auth0Subject },
defaults: {
Expand Down
23 changes: 16 additions & 7 deletions web/src/components/access-requests/AccessRequestCreateDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
color="primary"
v-bind="dialogProps"
>
{{ accessType === AccessTypes.SELF_SERVE_ACCESS ? "Subscribe" : "Request Access" }}
{{ panelAndButtonLabel }}
</v-btn>
</template>
<v-form
Expand All @@ -17,7 +17,7 @@
@submit.prevent="createAndClose"
>
<v-card :loading="isLoading">
<v-card-title class="text-h5"> Request Access </v-card-title>
<v-card-title class="text-h5"> {{ panelAndButtonLabel }} </v-card-title>

<v-card-text v-if="isNil(accessRequest)">
<v-skeleton-loader type="card" />
Expand Down Expand Up @@ -96,7 +96,7 @@
type="submit"
variant="elevated"
>
Request
{{ submitButtonLabel }}
</v-btn>
</v-card-actions>
</v-card>
Expand All @@ -121,6 +121,7 @@ import UserGroupAutocomplete, {
UserGroupTypes,
} from "@/components/user-groups/UserGroupAutocomplete.vue"
import { AccessTypes } from "@/api/access-grants-api"
import { computed } from "vue"
const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -150,11 +151,19 @@ const accessRequest = ref<Partial<AccessRequest>>({
const router = useRouter()
const route = useRoute()
const showDialog = ref(route.query.showCreate === "true")
const showDialog = ref(route.query.showCreateRequest === "true")
const form = ref<InstanceType<typeof VForm> | null>(null)
const isLoading = ref(false)
const isValid = ref(false)
// TODO: consider breaking the dialog into two separate components
const panelAndButtonLabel = computed(() => {
return props.accessType === AccessTypes.SELF_SERVE_ACCESS ? "Subscribe" : "Request Access"
})
const submitButtonLabel = computed(() => {
return props.accessType === AccessTypes.SELF_SERVE_ACCESS ? "Subscribe" : "Request"
})
watch(
() => [props.datasetId, props.accessGrantId, props.requestorId],
() => {
Expand All @@ -167,13 +176,13 @@ watch(
() => showDialog.value,
(value) => {
if (value) {
if (route.query.showCreate === "true") {
if (route.query.showCreateRequest === "true") {
return
}
router.push({ query: { showCreate: "true" } })
router.push({ query: { showCreateRequest: "true" } })
} else {
router.push({ query: { showCreate: undefined } })
router.push({ query: { showCreateRequest: undefined } })
}
}
)
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/datasets/DatasetsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
<template #item.actions="{ value: action, item: { slug } }">
<RequestAccessButton
v-if="action === DatasetTableActions.REQUEST_ACCESS"
:slug="slug"
class="action-buttons"
@mouseover="disableRowHighlight"
@mouseleave="removeDisableRowHighlight"
/>
<SubscribeToDatasetButton
v-else-if="action === DatasetTableActions.SUBSCRIBE"
:slug="slug"
class="action-buttons"
@mouseover="disableRowHighlight"
@mouseleave="removeDisableRowHighlight"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<v-btn
color="primary"
variant="outlined"
@click="requestAccess"
:to="{
name: 'DatasetDescriptionReadPage',
params: { slug },
query: { showCreateRequest: 'true' },
}"
>
Request Access
</v-btn>
</template>

<script lang="ts" setup>
function requestAccess() {
alert("TODO: Requesting access")
}
defineProps<{ slug: string }>()
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<v-btn
color="primary"
variant="outlined"
@click="subscribeToDataset"
:to="{
name: 'DatasetDescriptionReadPage',
params: { slug },
query: { showCreateRequest: 'true' },
}"
>
Subscribe
</v-btn>
</template>

<script lang="ts" setup>
function subscribeToDataset() {
alert("TODO: Subscribe to dataset")
}
defineProps<{ slug: string }>()
</script>
16 changes: 10 additions & 6 deletions web/src/components/qa-scenarios/QaScenariosCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ const ORDERED_ROLE_TYPES = [
RoleTypes.SYSTEM_ADMIN,
]
const nextRoleType = computed<RoleTypes | null>(() => {
const currentRoleType = computed<RoleTypes | null>(() => {
if (isNil(currentUser.value)) return null
const { roleTypes } = currentUser.value
const currentRoleType = roleTypes[0]
if (isNil(currentRoleType)) return null
return currentUser.value.roleTypes[0] || null
})
const nextRoleType = computed<RoleTypes | null>(() => {
if (isNil(currentRoleType.value)) return null
const currentIndex = ORDERED_ROLE_TYPES.indexOf(currentRoleType)
const currentIndex = ORDERED_ROLE_TYPES.indexOf(currentRoleType.value)
const nextIndex = (currentIndex + 1) % 4
return ORDERED_ROLE_TYPES[nextIndex]
})
Expand All @@ -78,7 +80,9 @@ const scenarios = computed<Scenario[]>(() => [
},
{
url: "/api/qa-scenarios/cycle-user-role-type",
label: `Cycle User Type To ${nextRoleType.value || "..."}`,
label: `Cycle User Type From "${currentRoleType.value || "..."}" To "${
nextRoleType.value || "..."
}"`,
},
])
Expand Down

0 comments on commit d16bcfd

Please sign in to comment.