Skip to content

Commit e43adc8

Browse files
committed
Only show edit schema button to authorized users in SubjectEditorDialog
1 parent 4ebc46e commit e43adc8

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

resources/ext.neowiki/src/components/SubjectEditor/SubjectEditorDialog.vue

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<p class="cdx-dialog__header__subtitle">
2323
{{ props.subject.getSchemaName() }}
2424
<a
25+
v-if="canEditSchema"
2526
class="ext-neowiki-subject-editor-dialog__schema-link"
2627
href="#"
2728
@click.prevent="isSchemaEditorOpen = true"
@@ -85,6 +86,7 @@ import { Schema } from '@/domain/Schema.ts';
8586
import { Statement } from '@/domain/Statement.ts';
8687
import { PropertyDefinitionList } from '@/domain/PropertyDefinitionList.ts';
8788
import SchemaEditorDialog from '@/components/SchemaEditor/SchemaEditorDialog.vue';
89+
import { NeoWikiServices } from '@/NeoWikiServices.ts';
8890

8991
const props = defineProps<{
9092
subject: Subject;
@@ -103,21 +105,36 @@ const open = ref( false );
103105
const isSchemaEditorOpen = ref( false );
104106
const subjectEditorRef = ref<SubjectEditorInstance | null>( null );
105107
const loadedSchema = ref<Schema | null>( null );
108+
const canEditSchema = ref( false );
106109

107110
onMounted( async () => {
108111
if ( props.subject ) {
109-
try {
110-
loadedSchema.value = await schemaStore.getOrFetchSchema( props.subject.getSchemaName() );
111-
} catch ( error ) {
112-
console.error( 'Failed to load schema:', error );
113-
mw.notify(
114-
`Failed to load schema ${ props.subject.getSchemaName() }: ${ error instanceof Error ? error.message : String( error ) }`,
115-
{ type: 'error' }
116-
);
117-
}
112+
await loadSchemaPermissions();
113+
await loadSchema();
118114
}
119115
} );
120116

117+
async function loadSchemaPermissions(): Promise<void> {
118+
try {
119+
canEditSchema.value = await NeoWikiServices.getSchemaAuthorizer().canEditSchema( props.subject.getSchemaName() );
120+
} catch ( error ) {
121+
console.error( 'Failed to check schema permissions:', error );
122+
canEditSchema.value = false;
123+
}
124+
}
125+
126+
async function loadSchema(): Promise<void> {
127+
try {
128+
loadedSchema.value = await schemaStore.getOrFetchSchema( props.subject.getSchemaName() );
129+
} catch ( error ) {
130+
console.error( 'Failed to load schema:', error );
131+
mw.notify(
132+
`Failed to load schema ${ props.subject.getSchemaName() }: ${ error instanceof Error ? error.message : String( error ) }`,
133+
{ type: 'error' }
134+
);
135+
}
136+
}
137+
121138
const schemaProperties = computed( (): PropertyDefinitionList =>
122139
loadedSchema.value?.getPropertyDefinitions() ?? new PropertyDefinitionList( [] )
123140
);

0 commit comments

Comments
 (0)