]> git.plutz.net Git - rawnet/commitdiff
shortcut function for permission check
authorPaul Hänsch <paul@plutz.net>
Thu, 30 Sep 2021 11:57:33 +0000 (13:57 +0200)
committerPaul Hänsch <paul@plutz.net>
Thu, 30 Sep 2021 11:57:33 +0000 (13:57 +0200)
page_channel.sh

index b1fd4c50d000448ea7b00312c399a8d94ae6fe29..ebba84d338d1fec16e4a021ae9da0579277a753a 100755 (executable)
@@ -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]