v0.2.0
This commit is contained in:
1 parent
23c7133fa9
commit
8c1b93c14e
16 files changed
+1187
-295
No files matched your search
+54
-2
@@ -42,11 +42,11 @@ func (m Model) updateMenu(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.screen = scrAudit
|
||||
m.refreshAudit()
|
||||
case "quit":
|
||||
return m, tea.Quit
|
||||
return m.attemptQuit()
|
||||
}
|
||||
return m, nil
|
||||
case "q":
|
||||
return m, tea.Quit
|
||||
return m.attemptQuit()
|
||||
}
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
@@ -57,3 +57,55 @@ func (m Model) updateMenu(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
func (m Model) viewMenu() string {
|
||||
return borderStyle.Render(m.menu.View())
|
||||
}
|
||||
|
||||
// unexportedUsers returns active users who have never had a key issued
|
||||
// (empty PublicKey) — created but forgotten before "Экспорт архивов".
|
||||
func unexportedUsers(m *Model) []string {
|
||||
st := m.loadState()
|
||||
var out []string
|
||||
for _, u := range st.Users {
|
||||
if u.PublicKey == "" {
|
||||
out = append(out, u.Username)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// attemptQuit is the only path that actually quits from the menu ("q" or
|
||||
// selecting "Выход"): if there are users created but never exported, it
|
||||
// warns instead of quitting straight away, since it's easy to create a
|
||||
// batch of users, get interrupted, and forget the export step entirely.
|
||||
// ctrl+c bypasses this deliberately, as an always-available hard exit.
|
||||
func (m Model) attemptQuit() (tea.Model, tea.Cmd) {
|
||||
pending := unexportedUsers(&m)
|
||||
if len(pending) == 0 {
|
||||
return m, tea.Quit
|
||||
}
|
||||
m.quitPending = pending
|
||||
m.quitReturnTo = scrMenu
|
||||
m.screen = scrQuitConfirm
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) updateQuitConfirm(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if key, ok := msg.(tea.KeyMsg); ok {
|
||||
switch key.String() {
|
||||
case "enter", "y":
|
||||
return m, tea.Quit
|
||||
case "esc", "n":
|
||||
m.screen = m.quitReturnTo
|
||||
return m, nil
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (m Model) viewQuitConfirm() string {
|
||||
body := warnStyle.Render("Есть пользователи, для которых ещё не сгенерирован ключ (не были в «Экспорт архивов»):") + "\n\n"
|
||||
for _, u := range m.quitPending {
|
||||
body += " - " + u + "\n"
|
||||
}
|
||||
body += "\nБез экспорта у них нет ключа и архива для передачи — доступ не работает.\n"
|
||||
body += "\n[enter/y] выйти всё равно [esc/n] вернуться"
|
||||
return borderStyle.Render(body)
|
||||
}
|
||||
Reference in new issue
Block a user