Skip to content

Commit d16bcfd

Browse files
Merge pull request #48 from icefoganalytics/issue-25/build-datasets-table-request-access-button-action
Build Datasets Table Request Access And Subscribe Buttons Actions
2 parents 930051c + bde2112 commit d16bcfd

File tree

7 files changed

+50
-23
lines changed

7 files changed

+50
-23
lines changed

api/src/controllers/qa-scenarios/apply-random-access-grants-controller.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { faker } from "@faker-js/faker"
22
import { CreationAttributes } from "sequelize"
33

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

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

9+
const AVAILABLE_ACCESS_TYPES = [
10+
AccessTypes.OPEN_ACCESS,
11+
AccessTypes.SELF_SERVE_ACCESS,
12+
AccessTypes.SCREENED_ACCESS,
13+
]
14+
915
export class ApplyRandomAccessGrantsController extends BaseController {
1016
async create() {
1117
try {
18+
await AccessRequest.destroy({ where: {}, force: true })
1219
await AccessGrant.destroy({ where: {}, force: true })
1320
await this.applyRandomAccessGrantsToDatasets()
1421
return this.response
@@ -36,7 +43,7 @@ export class ApplyRandomAccessGrantsController extends BaseController {
3643
creatorId: dataset.ownerId,
3744
// TODO: supportId: faker.helpers.arrayElement(users - dataset.owner).id,
3845
grantLevel: randomGrantLevel,
39-
accessType: faker.helpers.arrayElement(Object.values(AccessTypes)),
46+
accessType: faker.helpers.arrayElement(AVAILABLE_ACCESS_TYPES),
4047
isProjectDescriptionRequired: faker.datatype.boolean(),
4148
})
4249
)

api/src/middlewares/authorization-middleware.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type AuthorizationRequest = JwtRequest & {
1111
async function findOrCreateUserFromAuth0Token(token: string): Promise<User> {
1212
const { auth0Subject, email, firstName, lastName } = await auth0Integration.getUserInfo(token)
1313

14+
// TODO: move to ensure user service
1415
const [user, created] = await User.findOrCreate({
1516
where: { auth0Subject },
1617
defaults: {

web/src/components/access-requests/AccessRequestCreateDialog.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
color="primary"
99
v-bind="dialogProps"
1010
>
11-
{{ accessType === AccessTypes.SELF_SERVE_ACCESS ? "Subscribe" : "Request Access" }}
11+
{{ panelAndButtonLabel }}
1212
</v-btn>
1313
</template>
1414
<v-form
@@ -17,7 +17,7 @@
1717
@submit.prevent="createAndClose"
1818
>
1919
<v-card :loading="isLoading">
20-
<v-card-title class="text-h5"> Request Access </v-card-title>
20+
<v-card-title class="text-h5"> {{ panelAndButtonLabel }} </v-card-title>
2121

2222
<v-card-text v-if="isNil(accessRequest)">
2323
<v-skeleton-loader type="card" />
@@ -96,7 +96,7 @@
9696
type="submit"
9797
variant="elevated"
9898
>
99-
Request
99+
{{ submitButtonLabel }}
100100
</v-btn>
101101
</v-card-actions>
102102
</v-card>
@@ -121,6 +121,7 @@ import UserGroupAutocomplete, {
121121
UserGroupTypes,
122122
} from "@/components/user-groups/UserGroupAutocomplete.vue"
123123
import { AccessTypes } from "@/api/access-grants-api"
124+
import { computed } from "vue"
124125
125126
const props = withDefaults(
126127
defineProps<{
@@ -150,11 +151,19 @@ const accessRequest = ref<Partial<AccessRequest>>({
150151
const router = useRouter()
151152
const route = useRoute()
152153
153-
const showDialog = ref(route.query.showCreate === "true")
154+
const showDialog = ref(route.query.showCreateRequest === "true")
154155
const form = ref<InstanceType<typeof VForm> | null>(null)
155156
const isLoading = ref(false)
156157
const isValid = ref(false)
157158
159+
// TODO: consider breaking the dialog into two separate components
160+
const panelAndButtonLabel = computed(() => {
161+
return props.accessType === AccessTypes.SELF_SERVE_ACCESS ? "Subscribe" : "Request Access"
162+
})
163+
const submitButtonLabel = computed(() => {
164+
return props.accessType === AccessTypes.SELF_SERVE_ACCESS ? "Subscribe" : "Request"
165+
})
166+
158167
watch(
159168
() => [props.datasetId, props.accessGrantId, props.requestorId],
160169
() => {
@@ -167,13 +176,13 @@ watch(
167176
() => showDialog.value,
168177
(value) => {
169178
if (value) {
170-
if (route.query.showCreate === "true") {
179+
if (route.query.showCreateRequest === "true") {
171180
return
172181
}
173182
174-
router.push({ query: { showCreate: "true" } })
183+
router.push({ query: { showCreateRequest: "true" } })
175184
} else {
176-
router.push({ query: { showCreate: undefined } })
185+
router.push({ query: { showCreateRequest: undefined } })
177186
}
178187
}
179188
)

web/src/components/datasets/DatasetsTable.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@
3535
<template #item.actions="{ value: action, item: { slug } }">
3636
<RequestAccessButton
3737
v-if="action === DatasetTableActions.REQUEST_ACCESS"
38+
:slug="slug"
3839
class="action-buttons"
3940
@mouseover="disableRowHighlight"
4041
@mouseleave="removeDisableRowHighlight"
4142
/>
4243
<SubscribeToDatasetButton
4344
v-else-if="action === DatasetTableActions.SUBSCRIBE"
45+
:slug="slug"
4446
class="action-buttons"
4547
@mouseover="disableRowHighlight"
4648
@mouseleave="removeDisableRowHighlight"

web/src/components/datasets/datasets-table/RequestAccessButton.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
<v-btn
33
color="primary"
44
variant="outlined"
5-
@click="requestAccess"
5+
:to="{
6+
name: 'DatasetDescriptionReadPage',
7+
params: { slug },
8+
query: { showCreateRequest: 'true' },
9+
}"
610
>
711
Request Access
812
</v-btn>
913
</template>
1014

1115
<script lang="ts" setup>
12-
function requestAccess() {
13-
alert("TODO: Requesting access")
14-
}
16+
defineProps<{ slug: string }>()
1517
</script>

web/src/components/datasets/datasets-table/SubscribeToDatasetButton.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
<v-btn
33
color="primary"
44
variant="outlined"
5-
@click="subscribeToDataset"
5+
:to="{
6+
name: 'DatasetDescriptionReadPage',
7+
params: { slug },
8+
query: { showCreateRequest: 'true' },
9+
}"
610
>
711
Subscribe
812
</v-btn>
913
</template>
1014

1115
<script lang="ts" setup>
12-
function subscribeToDataset() {
13-
alert("TODO: Subscribe to dataset")
14-
}
16+
defineProps<{ slug: string }>()
1517
</script>

web/src/components/qa-scenarios/QaScenariosCard.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ const ORDERED_ROLE_TYPES = [
5151
RoleTypes.SYSTEM_ADMIN,
5252
]
5353
54-
const nextRoleType = computed<RoleTypes | null>(() => {
54+
const currentRoleType = computed<RoleTypes | null>(() => {
5555
if (isNil(currentUser.value)) return null
5656
57-
const { roleTypes } = currentUser.value
58-
const currentRoleType = roleTypes[0]
59-
if (isNil(currentRoleType)) return null
57+
return currentUser.value.roleTypes[0] || null
58+
})
59+
60+
const nextRoleType = computed<RoleTypes | null>(() => {
61+
if (isNil(currentRoleType.value)) return null
6062
61-
const currentIndex = ORDERED_ROLE_TYPES.indexOf(currentRoleType)
63+
const currentIndex = ORDERED_ROLE_TYPES.indexOf(currentRoleType.value)
6264
const nextIndex = (currentIndex + 1) % 4
6365
return ORDERED_ROLE_TYPES[nextIndex]
6466
})
@@ -78,7 +80,9 @@ const scenarios = computed<Scenario[]>(() => [
7880
},
7981
{
8082
url: "/api/qa-scenarios/cycle-user-role-type",
81-
label: `Cycle User Type To ${nextRoleType.value || "..."}`,
83+
label: `Cycle User Type From "${currentRoleType.value || "..."}" To "${
84+
nextRoleType.value || "..."
85+
}"`,
8286
},
8387
])
8488

0 commit comments

Comments
 (0)