Skip to content

Post update policy incorrectly rejects update #825

@ymc9

Description

@ymc9

ZModel

model User {
    id    Int     @id @default(autoincrement())
    role String
  
    @@allow('read', true)
    @@allow('update', auth().id == id || auth().role == 'superadmin' || auth().role == 'admin')
    @@deny('update', 
        (role == 'superadmin' && auth().id != id) 
        || (role == 'admin' && auth().id != id && auth().role != 'superadmin') 
        || (role != future().role && auth().role != 'admin' && auth().role != 'superadmin') 
        || (role != future().role && future().role == 'superadmin') 
        || (role != future().role && future().role == 'admin' && auth().role != 'superadmin')
    )
}

TS

const admin = await prisma.user.create({
    data: { role: 'admin' },
});

const user = await prisma.user.create({
    data: { role: 'customer' },
});

// the following line should succeed but got regjected
await enhance(prisma, { user: admin }).user.update({
    where: { id: user.id },
    data: { role: 'staff' },
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions