(zettel (meta (back "00001012051200 00001012051400 00001012053200 00001012053300 00001012053400 00001012054200") (backward "00001012051200 00001012051400 00001012053200 00001012053300 00001012053400 00001012054200") (box-number "1") (created "20220201173115") (forward "00001003000000 00001006020400 00001010000000 00001010040100 00001010040200 00001010070200 00001010070300") (modified "20230807164817") (published "20230807164817") (role "manual") (syntax "zmk") (tags "#api #manual #reference #zettelstore") (title "API: Encoding of Zettel Access Rights")) (rights 4) (encoding "") (content "Various API calls return a symbolic expression list ''(rights N)'', with ''N'' as a number, that encodes the access rights the user currently has.\n''N'' is an integer number between 0 and 62.[^Not all values in this range are used.]\n\nThe value \"\"0\"\" signals that something went wrong internally while determining the access rights.\n\nA value of \"\"1\"\" says, that the current user has no access right for the given zettel.\nIn most cases, this value will not occur, because only zettel are presented, which are at least readable by the current user.\n\nValues \"\"2\"\" to \"\"62\"\" are binary encoded values, where each bit signals a special right.\n\n|=Bit number:|Bit value:|Meaning\n| 1 | 2 | User is allowed to create a new zettel\n| 2 | 4 | User is allowed to read the zettel\n| 3 | 8 | User is allowed to update the zettel\n| 4 | 16 | User is allowed to rename the zettel\n| 5 | 32 | User is allowed to delete the zettel\n\nThe algorithm to calculate the actual access rights from the value is relatively simple:\n# Search for the biggest bit value that is less than the rights value.\n This is an access right for the current user.\n# Subtract the bit value from the rights value.\n Remember the difference as the new rights value.\n# If it is greater than zero, move to step 1.\n\nAs an example, let's assume a rights value of 42:\n# The first right is the right to delete a zettel.\n The new value of the rights value is now 10 (42-32).\n# The next right is the right to update a zettel (16 > 10, but 8 < 10).\n The new value of the rights value is now 2 (10-8).\n# The last right is the right to create a new zettel.\n The rights value is now zero, the algorithm ends.\n\nIn practice, not every rights value will occur.\nA Zettelstore in [[read-only mode|00001010000000#read-only]] will always return the value 4.\nSimilar, a Zettelstore that you started with a [[double-click|00001003000000]] will return either the value \"\"6\"\" (reading and updating) or the value \"\"62\"\" (all operations are allowed).\n\nIf you have added an additional [[user|00001010040200]] to your Zettelstore, this might change.\nThe access rights are calculated depending on [[enabled authentication|00001010040100]], on the [[user role|00001010070300]] of the current user, on [[visibility rules|00001010070200]] for a given zettel and on the [[read-only status|00001006020400]] for the zettel."))