'Lock the given instance.'

def lock(self, context, instance):

    is_owner = (instance.project_id == context.project_id)
    if (instance.locked and is_owner):
        return
    context = context.elevated()
    LOG.debug('Locking', instance=instance)
    instance.locked = True
    instance.locked_by = ('owner' if is_owner else 'admin')
    instance.save()
