From 1659fe8d4fdabc8fe1e7ff0df9c25173d022aec9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 30 Sep 2021 13:57:33 +0200 Subject: [PATCH] shortcut function for permission check --- page_channel.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/page_channel.sh b/page_channel.sh index b1fd4c5..ebba84d 100755 --- a/page_channel.sh +++ b/page_channel.sh @@ -59,6 +59,14 @@ update_channel(){ fi } +AUTHOR(){ + if [ "$channel" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then + return 0 + else + return 1 + fi +} + # Video # ID NAME DESCRIPTION RESX RESY LENGTH COVER STATUS UPLOADER HITS @@ -87,7 +95,7 @@ update_channel(){ REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" elif [ ! "$USER_ID" ]; then REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" - elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then + elif ! AUTHOR; then REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" elif update_channel "$channel" "$(POST name)" "$(POST description)" \ "" "" "$USER_ID" "" ""; then @@ -102,7 +110,7 @@ update_channel(){ newvideo) video="$(POST video |checkid)" - [ "$channel" -a "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ + AUTHOR \ && mkdir -p -- "${_DATA}/${channel}/" if [ ! "$video" ]; then @@ -111,7 +119,7 @@ update_channel(){ REDIRECT "${_BASE}/channel/#ERROR_NOCHANNEL" elif [ ! "$USER_ID" ]; then REDIRECT "${_BASE}/channel/${channel}/#ERROR_NOTLOGGEDIN" - elif [ "${CHANNEL_AUTHORS##*${USER_ID}*}" ]; then + elif ! AUTHOR; then REDIRECT "${_BASE}/channel/${channel}/#ERROR_UPDATE_NOTALLOWED" elif LOCK "$vid_db"; then if grep -q '^${video} ' "$vid_db"; then @@ -138,10 +146,10 @@ w_video(){ thumb="${_BASE}/${CID}/thumb_${ID}.jpg" [ "$NAME" = \\ ] && NAME="(Unnamed Video)" printf '[div .video .thumb - [h3 [a href="%s/" . %s]] + [h3 [a href="%s/channel/%s/%s/" . %s]] [figure [img src="%s" alt=""]] [div .description . %s] - ]' "$ID" "$(UNSTRING "$NAME" |HTML)" "$thumb" "$(UNSTRING "$DESCR_CACHE")" + ]' "$_BASE" "$CID" "$ID" "$(UNSTRING "$NAME" |HTML)" "$thumb" "$(UNSTRING "$DESCR_CACHE")" else return 1 fi @@ -184,8 +192,7 @@ w_channel_list(){ if [ "$channel" -a "$video" ]; then . ${_EXEC}/page_video.sh elif [ "$channel" -a "$action" = edit ]; then - [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ - || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED" + AUTHOR || REDIRECT "${_BASE}/${channel}/#ERROR_EDIT_NOTALLOWED" yield_page "$CHANNEL_NAME - Edit" "channel edit" <<-EOF [form .channel .edit method=POST [input name="name" value="$(HTML "$CHANNEL_NAME")" placeholder="Channel Name"] @@ -197,16 +204,13 @@ elif [ "$channel" -a "$action" = edit ]; then elif [ "$channel" ]; then yield_page "$CHANNEL_NAME" "channel" <<-EOF [nav [a href="../" Channels] - [span $(HTML "${CHANNEL_NAME:-(Unnamed Channel)}")] - $( [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ - && printf ' - [a href="edit" edit]' - ) + $(AUTHOR && printf ' - [a href="edit" edit]') ] [h1 .name $(HTML "$CHANNEL_NAME")] [div .description . ${CHANNEL_DESCR_CACHE}] [h1 .videos Videos] [div .videos . $( - [ "$USER_ID" -a ! "${CHANNEL_AUTHORS##*${USER_ID}*}" ] \ - && printf ' + AUTHOR && printf ' [form .video .newvideo method=POST [hidden "video" "%s"] [submit "action" "newvideo" New Video] -- 2.39.2