Readonly flag for the individual page...?

Hello, I’m new to Silverbullet.

First of all, thanks for devs. Now I can have a dream to escape from all the heavy and commercial note services… But there are many questions because I’m not good at English and programming.

My current issue is: Is there a flag or something to set the individual page readonly? Quick edit is cool feature and I love it. And it will be great if I can protect the system pages from unexpected edit.

The following block will let you make a page read-only if it has the tag “uneditable” (you can change that if you want)

EDIT: This approach has some massive flaws

It takes a second for the changes to take effect though… sadly I couldn’t find a page load event to listen to.

event.listen {
  name = "cron:secondPassed",
  run = function(e)
    meta = editor.getCurrentPageMeta()
    isReadOnly = editor.getUiOption("forcedROMode")
    if not isReadOnly and table.includes(meta.tags, "uneditable") then
      editor.setUiOption("forcedROMode", true)
      editor.rebuildEditorState()
    elseif isReadOnly and not table.includes(meta.tags, "uneditable") then
      editor.setUiOption("forcedROMode", false)
      editor.rebuildEditorState()
    end
  end
}

A big hint! Thank you. I’m testing possible events found in reference.

I’m using one of:

  • hooks:renderBottomWidgets
  • hooks:renderTopWidgets

Works great! :+1:

I tried another way but without success :hot_face:

function setPerm()
  
  pageName = editor.getCurrentPage()
  if not pageName then return end
  local permission = query [[from index.tag "page" where name == editor.getCurrentPage() select perm]]
  editor.flashNotification(permission)
  
  if unpack(permission) == "rw" then
    editor.flashNotification("ok")
    local objects = {perm = "ro"}
    else
    editor.flashNotification("not")
    local objects = {perm = "rw"}
  end

  index.indexObjects(pageName, objects)
  
  return
  end

(info : editor.flashNotification just for control)
Result → Error: can’t access property Symbol.iterator, t is null.

After much research, it seems impossible to change the “perm” attribute.
For what ?

I found this to recurse when editor.rebuildEditorState() was called and cause other issues, kinda weird

permission is derived from the file’s permissions on the operating system. So, one way to modify it is running shell commands on the server.

Source:
getPageMeta(): silverbullet/client/space.ts at 5b03ed872cf0764ad7f01c30f21a84f7cc76a6b0 · silverbulletmd/silverbullet · GitHub

GetFileMeta(): silverbullet/server/disk_space_primitives.go at 5b03ed872cf0764ad7f01c30f21a84f7cc76a6b0 · silverbulletmd/silverbullet · GitHub

hooks:renderBottomWidgets works nearly perfect, but maybe we need an event name like hooks:renderComplete

So it looks like we need a new page attribute to block any changes on individual page during a silverbullet session. This also could be a partial solution to the problem identified when viewing on mobile.