refactor: reuse user_in_group helper for membership checks
cmd_join, cmd_invite, and cmd_list each inlined the id -nG | tr | grep pipeline instead of calling the existing user_in_group helper. cmd_list also re-forked id once per party in its loop; now the caller's groups are captured once before the loop. Also fold user_in_party_group (one caller) into require_caller_in_group and drop the wrapper.
This commit is contained in:
parent
698fff91ee
commit
9980d2918a
1 changed files with 7 additions and 9 deletions
16
party
16
party
|
|
@ -141,11 +141,6 @@ user_in_group() {
|
|||
id -nG "$1" 2>/dev/null | tr ' ' '\n' | grep -qx "$2"
|
||||
}
|
||||
|
||||
# Boolean: is the named user in TMUX_PARTY_GROUP?
|
||||
user_in_party_group() {
|
||||
user_in_group "$1" "$TMUX_PARTY_GROUP"
|
||||
}
|
||||
|
||||
# Print the first PARTY_GROUP_CANDIDATES entry the caller belongs to;
|
||||
# print nothing and return 1 when the caller is in none of them.
|
||||
pick_host_group() {
|
||||
|
|
@ -164,7 +159,7 @@ pick_host_group() {
|
|||
# are stopped by the FS perimeter itself (EACCES at the per-party dir)
|
||||
# and get the friendlier group-gate message in cmd_join.
|
||||
require_caller_in_group() {
|
||||
if ! user_in_party_group "$USER"; then
|
||||
if ! user_in_group "$USER" "$TMUX_PARTY_GROUP"; then
|
||||
cat >&2 <<EOF
|
||||
party: you ($USER) are not in the '$TMUX_PARTY_GROUP' group.
|
||||
|
||||
|
|
@ -1201,7 +1196,7 @@ EOF
|
|||
# at roster_list; this preflight just turns that into a friendlier
|
||||
# error than "party not found" when membership is the actual cause.
|
||||
party_group="${RR_GROUP:-$TMUX_PARTY_GROUP}"
|
||||
if ! id -nG "$USER" 2>/dev/null | tr ' ' '\n' | grep -qx "$party_group"; then
|
||||
if ! user_in_group "$USER" "$party_group"; then
|
||||
cat >&2 <<EOF
|
||||
party: '$RR_PARTY_NAME' uses group '$party_group'; you ($USER) are not a member.
|
||||
|
||||
|
|
@ -1440,7 +1435,7 @@ cmd_invite() {
|
|||
# Warn-and-proceed (rather than hard-fail) so a later usermod -aG
|
||||
# doesn't require a re-invite.
|
||||
invite_group="${RR_GROUP:-$TMUX_PARTY_GROUP}"
|
||||
if ! id -nG "$user" 2>/dev/null | tr ' ' '\n' | grep -qx "$invite_group"; then
|
||||
if ! user_in_group "$user" "$invite_group"; then
|
||||
cat >&2 <<EOF
|
||||
party invite: warning, '$user' is not in group '$invite_group'.
|
||||
They will not be able to discover or join until added.
|
||||
|
|
@ -1531,6 +1526,9 @@ cmd_detach() {
|
|||
cmd_list() {
|
||||
_parse_no_args list "$@"
|
||||
found=0 lines='' first_group='' mixed=0
|
||||
# Capture the caller's groups once rather than forking `id` per
|
||||
# party in the loop below.
|
||||
_ls_groups=$(id -nG "$USER" 2>/dev/null | tr ' ' '\n')
|
||||
for rec in $(roster_list); do
|
||||
roster_read "$rec" || continue
|
||||
state=$(party_conn_state "$RR_SOCKET")
|
||||
|
|
@ -1544,7 +1542,7 @@ cmd_list() {
|
|||
# whose group the caller isn't in. Confidentiality still rides on
|
||||
# the FS perimeter alone.
|
||||
list_group="${RR_GROUP:-$TMUX_PARTY_GROUP}"
|
||||
id -nG "$USER" 2>/dev/null | tr ' ' '\n' | grep -qx "$list_group" || continue
|
||||
printf '%s\n' "$_ls_groups" | grep -qx "$list_group" || continue
|
||||
# The group tag only earns its column when the visible parties
|
||||
# disagree on it. Which group gates a party is decided per host
|
||||
# (auto-selection), so there is no default to compare against:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue