╭ changed ─────────╮ │src/event/Repo.zig│ ╰──────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────╮ │24 public, │ │25 }; │ │26 │ │27 -// what a user may do in a repo, ordered so a higher role includes the lower ones│ │27 +// what a user may do in a repo, ordered so a higher role includes the lower │ │28 +// ones. holding no role is a null, not a value. │ │29 pub const Role = enum { │ │29 - none, │ │30 read, │ │31 write, │ │32 owner, │ ╰─────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────╮ │40 pub fn canModify(self: Role, user_email: []const u8, author_email_maybe: ?[]const u8) bool {│ │41 if (self.atLeast(.write)) return true; │ │42 const author_email = author_email_maybe orelse return false; │ │43 - return self.atLeast(.read) and std.mem.eql(u8, user_email, author_email); │ │43 + return std.mem.eql(u8, user_email, author_email); │ │44 } │ │45 }; │ │46 │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │47 pub const name_max_len = 32; │ │48 │ │49 -// the role `user_id_maybe` holds in the repo: its creator owns it, and anyone │ │50 -// else gets the higher of the base role and their grant. `user_moment` is the │ │51 -// owner's, which holds the grants. null is a logged-out user. │ │49 +// the role `user_id_maybe` holds in the repo, or null when they hold none: its│ │50 +// creator owns it, and anyone else gets the higher of the base role and their │ │51 +// grant. `user_moment` is the owner's, which holds the grants. a null user is │ │52 +// logged out. │ │53 pub fn roleOf( │ │54 comptime DB: type, │ │55 comptime hash_kind: hash.HashKind, │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │58 record: Record, │ │59 repo_id: *const [evt.event_id_size]u8, │ │60 user_id_maybe: ?[evt.event_id_size]u8, │ │60 -) !Role { │ │61 +) !?Role { │ │62 // what the access fields give everyone, logged in or not │ │62 - const base: Role = if (record.event.write_access == .public) .write else if (record.event.read_access == .public) .read else .none; │ │63 - const user_id = user_id_maybe orelse return base; │ │63 + const base_maybe: ?Role = if (record.event.write_access == .public) .write else if (record.event.read_access == .public) .read else null;│ │64 + const user_id = user_id_maybe orelse return base_maybe; │ │65 if (std.mem.eql(u8, record.event.user_id, &user_id)) return .owner; │ │66 │ │66 - const granted = (try evt.Grant.readRole(DB, hash_kind, user_moment, arena, repo_id, &user_id)) orelse return base; │ │67 + const granted = (try evt.Grant.readRole(DB, hash_kind, user_moment, arena, repo_id, &user_id)) orelse return base_maybe; │ │68 + const base = base_maybe orelse return granted; │ │69 return if (granted.atLeast(base)) granted else base; │ │70 } │ │71 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────╮ │150 event_id: [evt.event_id_size]u8, │ │151 }; │ │152 │ │151 -// a repo as one viewer sees it │ │153 +// a repo as one viewer sees it. without a role, the viewer may not see it.│ │154 pub const RepoWithRole = struct { │ │155 repo: Record, │ │156 event_id: [evt.event_id_size]u8, │ ╰────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────╮ │155 - role: Role, │ │157 + role: ?Role, │ │158 }; │ │159 │ │160 // read a repo by its name from its owner's user repo│ ╰──────────────────────────────────────────────────────────╯