Add nidusctl admin CLI for managing calendar/address-book shares
- tools/nidusctl: subcommands `calendar {share,unshare,shares}` and
`addressbook {share,unshare,shares}`, thin wrapper around internal/db.
Warns (non-fatal) if owner/user isn't in config.yaml.
- internal/db: add SharesOfAddressBook (owner-perspective query, mirrors
SharesOfCalendar) needed by the CLI.
- internal/db: db.Open now creates the parent data directory itself, so
the CLI works standalone without requiring the server to have run first.
- Update Makefile (build bin/nidusctl, new 'nidusctl' target), README and
copilot-instructions with usage docs.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -178,6 +178,33 @@ func (d *DB) UnshareAddressBook(owner, bookName, sharedWith string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SharesOfAddressBook lists everyone owner's address book bookName has
|
||||
// been shared with.
|
||||
func (d *DB) SharesOfAddressBook(owner, bookName string) ([]AddressBookShare, error) {
|
||||
rows, err := d.conn.Query(`
|
||||
SELECT owner, addressbook_name, shared_with, permission
|
||||
FROM addressbook_shares
|
||||
WHERE owner = ? AND addressbook_name = ?
|
||||
ORDER BY shared_with`,
|
||||
owner, bookName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("listing address book shares: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var shares []AddressBookShare
|
||||
for rows.Next() {
|
||||
var s AddressBookShare
|
||||
var perm string
|
||||
if err := rows.Scan(&s.Owner, &s.AddressBookName, &s.SharedWith, &perm); err != nil {
|
||||
return nil, fmt.Errorf("scanning address book share: %w", err)
|
||||
}
|
||||
s.Permission = Permission(perm)
|
||||
shares = append(shares, s)
|
||||
}
|
||||
return shares, rows.Err()
|
||||
}
|
||||
|
||||
// AddressBooksSharedWith lists all address books (from any owner) that
|
||||
// have been shared with user.
|
||||
func (d *DB) AddressBooksSharedWith(user string) ([]AddressBookShare, error) {
|
||||
|
||||
Reference in New Issue
Block a user