Skip to content

Commit 8d600f5

Browse files
SharonStratsGPT-5.4 Mini
andcommitted
Address feedback from PR
Prompt: Should I address the feedback about errors now, as I am going to implement error handling later. If so please add a temporary fix. Co-authored-by: GPT-5.4 Mini <gpt-5.4-mini@openai.com>
1 parent 4ca3692 commit 8d600f5

3 files changed

Lines changed: 138 additions & 45 deletions

File tree

‎src/components/access-control-modal/AccessControlModal.ts‎

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default class AccessControlModal extends WebComponent {
8686
this.accessGrantRoles = this.accessGrants?.map(item => this.getAuthorizationRole(item)) ?? []
8787
this.authenticatedAccessRoleValue = this.getAuthenticatedAccessRole()
8888
this.publicAccessRoleValue = this.getPublicAccessRole()
89-
void this.refreshAccessGrantLabels()
89+
this.refreshAccessGrantLabels()
9090
}
9191
}
9292

@@ -107,7 +107,7 @@ export default class AccessControlModal extends WebComponent {
107107
}
108108
}
109109

110-
return this.getAuthorizationSubjectLabel(authorization)
110+
return this.getAuthorizationSubjectLabel(this.getSharedAuthorization(authorization))
111111
}))
112112

113113
if (this.accessGrants === grants) {
@@ -118,6 +118,7 @@ export default class AccessControlModal extends WebComponent {
118118
private getAccessGrantEntries () {
119119
return (this.accessGrants ?? [])
120120
.map((authorization, index) => {
121+
authorization = this.getSharedAuthorization(authorization)
121122
const subjectLabel = this.getAccessGrantSubjectLabel(authorization, index)
122123

123124
return {
@@ -139,10 +140,10 @@ export default class AccessControlModal extends WebComponent {
139140
}
140141

141142
private getSharedAccessGrantEntries () {
142-
return this.getAccessGrantEntries().filter(({ authorization }) => !this.isGeneralAccessAuthorization(authorization))
143+
return this.getAccessGrantEntries().filter(({ authorization }) => this.getAuthorizationSubjectIris(authorization).length > 0)
143144
}
144145

145-
private renderAccessGrants() {
146+
private renderAccessGrants () {
146147
const query = this.searchValue.trim().toLowerCase()
147148
const accessGrants = this.getSharedAccessGrantEntries().filter(({ subjectLabel }) => {
148149
if (!query) {
@@ -239,8 +240,11 @@ export default class AccessControlModal extends WebComponent {
239240
return solidLogicSingleton.acl.roleFromModes(authorization.mode)
240241
}
241242

242-
private isGeneralAccessAuthorization (authorization: Authorization): boolean {
243-
return authorization.agentClass.includes(Authenticated.iri) || authorization.agentClass.includes(Public.iri)
243+
private getSharedAuthorization (authorization: Authorization): Authorization {
244+
return {
245+
...authorization,
246+
agentClass: authorization.agentClass.filter(iri => iri !== Authenticated.iri && iri !== Public.iri)
247+
}
244248
}
245249

246250
private getAuthenticatedAccessRole (): AccessRole {
@@ -493,39 +497,39 @@ export default class AccessControlModal extends WebComponent {
493497

494498
return `Share "${subjectLabel}"`
495499
}
496-
500+
497501
protected render () {
498502
const dialogTitle = this.getDialogTitle()
499-
503+
500504
return html`
501-
<solid-ui-dialog title=${dialogTitle}>
502-
<form @submit=${this.onSubmit}>
503-
<solid-ui-dialog-content>
504-
${this.renderAddAccessForm()}
505-
${this.renderAccessGrantsSection()}
506-
${this.renderGeneralAccessSection()}
507-
</solid-ui-dialog-content>
508-
509-
<solid-ui-dialog-footer>
510-
<div class="access-control-footer-actions">
511-
<solid-ui-button
512-
variant="secondary"
513-
@click=${this.onCancelClick}
514-
>
515-
Cancel
516-
</solid-ui-button>
517-
<solid-ui-button
518-
?disabled=${!this.hasUnsavedChanges() || this.submitting}
519-
?loading=${this.submitting}
520-
type="button"
521-
@click=${this.onSaveClick}
522-
>
523-
Save Changes
524-
</solid-ui-button>
525-
</div>
526-
</solid-ui-dialog-footer>
527-
</form>
528-
</solid-ui-dialog>
505+
<solid-ui-dialog title=${dialogTitle}>
506+
<form @submit=${this.onSubmit}>
507+
<solid-ui-dialog-content>
508+
${this.renderAddAccessForm()}
509+
${this.renderAccessGrantsSection()}
510+
${this.renderGeneralAccessSection()}
511+
</solid-ui-dialog-content>
512+
513+
<solid-ui-dialog-footer>
514+
<div class="access-control-footer-actions">
515+
<solid-ui-button
516+
variant="secondary"
517+
@click=${this.onCancelClick}
518+
>
519+
Cancel
520+
</solid-ui-button>
521+
<solid-ui-button
522+
?disabled=${!this.hasUnsavedChanges() || this.submitting}
523+
?loading=${this.submitting}
524+
type="button"
525+
@click=${this.onSaveClick}
526+
>
527+
Save Changes
528+
</solid-ui-button>
529+
</div>
530+
</solid-ui-dialog-footer>
531+
</form>
532+
</solid-ui-dialog>
529533
`
530534
}
531535

@@ -545,7 +549,11 @@ export default class AccessControlModal extends WebComponent {
545549
}
546550

547551
if (this.principalInputValue.trim()) {
548-
await this.commitPrinciplesFromInputSafely()
552+
const committed = await this.commitPrinciplesFromInputSafely()
553+
554+
if (!committed) {
555+
return
556+
}
549557
}
550558

551559
await this.saveAccessChanges()
@@ -620,7 +628,7 @@ export default class AccessControlModal extends WebComponent {
620628
return
621629
}
622630

623-
void this.queuePendingPrinciples([option.value], this.addAccessRoleValue, option.label)
631+
this.queuePendingPrinciples([option.value], this.addAccessRoleValue, option.label)
624632
}
625633

626634
private onSearchInput (event: Event) {
@@ -727,7 +735,7 @@ export default class AccessControlModal extends WebComponent {
727735
return undefined
728736
}
729737

730-
const subjects = this.getAuthorizationSubjectEntries(authorization)
738+
const subjects = this.getAuthorizationSubjectEntries(this.getSharedAuthorization(authorization))
731739
if (!subjects.length) {
732740
return undefined
733741
}
@@ -783,8 +791,7 @@ export default class AccessControlModal extends WebComponent {
783791
return false
784792
}
785793

786-
await this.queuePendingPrinciples([rawValue], this.addAccessRoleValue, undefined, rawValue)
787-
return true
794+
return this.queuePendingPrinciples([rawValue], this.addAccessRoleValue, undefined, rawValue)
788795
}
789796

790797
private async commitPrinciplesFromInputSafely (): Promise<boolean> {
@@ -802,7 +809,7 @@ export default class AccessControlModal extends WebComponent {
802809
role: AccessRole = this.addAccessRoleValue,
803810
preferredLabel?: string,
804811
inputSnapshot?: string
805-
) {
812+
): Promise<boolean> {
806813
const snapshot = inputSnapshot ?? this.principalInputValue.trim()
807814
const pendingGrantResults = await Promise.all(principles.map(async principle => this.createPendingAccessGrant(principle, role, preferredLabel)))
808815
const newGrants = pendingGrantResults.flatMap(result => ('grant' in result ? [result.grant] : []))
@@ -811,17 +818,25 @@ export default class AccessControlModal extends WebComponent {
811818
.map(result => `${result.principle} (${result.error})`)
812819

813820
if (!newGrants.length) {
821+
if (failedGrants.length) {
822+
this.failed = true
823+
}
814824
this.logPendingGrantFailures(failedGrants, false)
815-
return
825+
return false
816826
}
817827

818828
const merged = [...this.pendingAccessGrants, ...newGrants]
819829
this.pendingAccessGrants = this.dedupePendingAccessGrants(merged)
830+
if (failedGrants.length) {
831+
this.failed = true
832+
}
820833
this.logPendingGrantFailures(failedGrants, true)
821834

822-
if (this.principalInputValue.trim() === snapshot) {
835+
if (!failedGrants.length && this.principalInputValue.trim() === snapshot) {
823836
this.principalInputValue = ''
824837
}
838+
839+
return failedGrants.length === 0
825840
}
826841

827842
private async createPendingAccessGrant (
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import AccessControlModal from './AccessControlModal'
22

33
export { AccessControlModal }
4-
export default AccessControlModal
4+
export default AccessControlModal

‎test/components/access-control-modal.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,64 @@ describe('AccessControlModal submit', () => {
384384
document.body.removeChild(element)
385385
})
386386

387+
it.each([
388+
'http://www.w3.org/ns/auth/acl#AuthenticatedAgent',
389+
'http://xmlns.com/foaf/0.1/Agent'
390+
])('retains non-general subjects from an authorization containing %s', async (generalClass) => {
391+
const element = document.createElement('solid-ui-access-control-modal') as any
392+
const agent = 'https://alice.example.com/profile/card.ttl#me'
393+
const group = 'https://example.com/group'
394+
const agentClass = 'https://example.com/team'
395+
element.subjectUri = 'https://example.com/resource.ttl'
396+
element.accessGrants = [{
397+
agent: [agent],
398+
agentGroup: [group],
399+
agentClass: [generalClass, agentClass],
400+
mode: ['Read']
401+
}]
402+
403+
document.body.appendChild(element)
404+
await element.updateComplete
405+
await element.refreshAccessGrantLabels()
406+
await element.updateComplete
407+
408+
const expectedLabel = element.getAuthorizationSubjectLabel({
409+
agent: [agent],
410+
agentGroup: [group],
411+
agentClass: [agentClass],
412+
mode: ['Read']
413+
})
414+
const entries = element.getSharedAccessGrantEntries()
415+
expect(entries).toHaveLength(1)
416+
expect(entries[0].authorization.agentClass).toEqual([agentClass])
417+
expect(entries[0].subjectLabel).toBe(expectedLabel)
418+
expect(element.accessGrants[0].agentClass).toEqual([generalClass, agentClass])
419+
expect(element.shadowRoot.querySelector('.access-grants-list h3').textContent.trim()).toBe(expectedLabel)
420+
const searchOptions = [...element.shadowRoot.querySelectorAll('solid-ui-combobox.access-grants-search-input solid-ui-combobox-option')]
421+
.map((option: Element) => option.textContent?.trim())
422+
expect(searchOptions).toEqual([expectedLabel])
423+
424+
element.searchValue = 'card.ttl'
425+
await element.updateComplete
426+
expect(element.shadowRoot.querySelector('.access-grants-list h3').textContent.trim()).toBe(expectedLabel)
427+
428+
const roleSelect = element.shadowRoot.querySelector('.access-grants-list solid-ui-combobox')
429+
roleSelect.dispatchEvent(new CustomEvent('change', {
430+
bubbles: true,
431+
composed: true,
432+
detail: { option: { value: 'Editor', label: 'Editor' } }
433+
}))
434+
await element.updateComplete
435+
await element.onSaveClick()
436+
437+
expect(planGrant.mock.calls.map(([, subject]) => subject)).toEqual([
438+
{ type: 'agent', iri: agent },
439+
{ type: 'agentGroup', iri: group },
440+
{ type: 'agentClass', iri: agentClass }
441+
])
442+
document.body.removeChild(element)
443+
})
444+
387445
it('persists a changed shared access grant on save', async () => {
388446
const element = document.createElement('solid-ui-access-control-modal') as any
389447
element.subjectUri = 'https://example.com/resource.ttl'
@@ -415,6 +473,26 @@ describe('AccessControlModal submit', () => {
415473
document.body.removeChild(element)
416474
})
417475

476+
it('aborts saving when principal lookup fails', async () => {
477+
const element = document.createElement('solid-ui-access-control-modal') as any
478+
element.subjectUri = 'https://example.com/resource.ttl'
479+
element.principalInputValue = 'not-a-principal'
480+
element.publicAccessRoleValue = 'Viewer'
481+
482+
document.body.appendChild(element)
483+
await element.updateComplete
484+
485+
await element.onSaveClick()
486+
487+
expect(planGrant).not.toHaveBeenCalled()
488+
expect(planRevoke).not.toHaveBeenCalled()
489+
expect(applyPlan).not.toHaveBeenCalled()
490+
expect(element.principalInputValue).toBe('not-a-principal')
491+
expect(element.failed).toBe(true)
492+
493+
document.body.removeChild(element)
494+
})
495+
418496
it('applies a shared row change to every subject represented by the authorization', async () => {
419497
const element = document.createElement('solid-ui-access-control-modal') as any
420498
element.subjectUri = 'https://example.com/resource.ttl'

0 commit comments

Comments
 (0)