Skip to content

Commit

Permalink
feat: add webhook configure permission in press role (frappe#2184)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt authored Sep 27, 2024
1 parent 8ee22e0 commit 707bf67
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 107 deletions.
12 changes: 10 additions & 2 deletions dashboard/src2/components/settings/DeveloperSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<ObjectList :options="sshKeyListOptions" />
</div>
<div
v-if="$session.hasWebhookConfigurationAccess"
class="mx-auto min-w-[48rem] max-w-3xl space-y-6 rounded-md border p-4"
>
<div class="flex items-center justify-between">
Expand Down Expand Up @@ -114,7 +115,7 @@
<script setup>
import { Badge, createResource } from 'frappe-ui';
import { toast } from 'vue-sonner';
import { computed, h, ref } from 'vue';
import { computed, h, onMounted, ref } from 'vue';
import { confirmDialog, icon } from '../../utils/components';
import ObjectList from '../ObjectList.vue';
import { getTeam } from '../../data/team';
Expand All @@ -125,6 +126,7 @@ import ActivateWebhookDialog from './ActivateWebhookDialog.vue';
import EditWebhookDialog from './EditWebhookDialog.vue';
import { useRouter } from 'vue-router';
import WebhookAttemptsDialog from './WebhookAttemptsDialog.vue';
import { session } from '../../data/session';
const $team = getTeam();
const router = useRouter();
Expand Down Expand Up @@ -296,7 +298,7 @@ const webhookListResource = createResource({
fields: ['name', 'enabled', 'endpoint']
},
initialData: [],
auto: true
auto: false
});
const deleteWebhook = createResource({
Expand Down Expand Up @@ -464,4 +466,10 @@ const onWebHookUpdated = activationRequired => {
showActivateWebhookDialog.value = true;
}
};
onMounted(() => {
if (session.hasWebhookConfigurationAccess) {
webhookListResource.fetch();
}
});
</script>
18 changes: 18 additions & 0 deletions dashboard/src2/components/settings/RoleConfigureDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
label="Allow Server Creation"
:disabled="adminAccess"
/>
<Switch
v-model="allowWebhookConfiguration"
label="Allow Webhook Configuration"
:disabled="adminAccess"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -252,6 +257,19 @@ export default {
{ onSuccess: this.$session.roles.reload }
);
}
},
allowWebhookConfiguration: {
get() {
return !!this.role?.allow_webhook_configuration;
},
set(value) {
this.$resources.role.setValue.submit(
{
allow_webhook_configuration: value
},
{ onSuccess: this.$session.roles.reload }
);
}
}
},
methods: {
Expand Down
5 changes: 5 additions & 0 deletions dashboard/src2/data/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export let session = reactive({
? session.roles.data.some(role => role.allow_billing)
: true
),
hasWebhookConfigurationAccess: computed(() =>
session.roles.data.length
? session.roles.data.some(role => role.allow_webhook_configuration)
: true
),
hasAppsAccess: computed(() =>
session.roles.data.length
? session.roles.data.some(role => role.allow_apps)
Expand Down
Loading

0 comments on commit 707bf67

Please sign in to comment.