| @@ -1,23 +1,25 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Folder sharing visibility logic. | |
| 3 | + * OpenStation — Folder sharing visibility logic. | |
| 4 | 4 | * |
| 5 | - * Computes which folders a viewer can see based on each folder's | |
| 6 | - * `share_mode` / `share_meta` columns: | |
| 5 | + * Computes which folders a viewer can see from each folder's | |
| 6 | + * `share_mode` plus the shares / decisions tables: | |
| 7 | 7 | * |
| 8 | 8 | * - `private` — owner only. |
| 9 | - * - `users` — owner + ids in `share_meta.users`. | |
| 10 | - * - `roles` — owner + users with any role in `share_meta.roles`. | |
| 11 | - * - `all` — every desktop-mode user on the site. | |
| 9 | + * - `users` / `roles` — owner + principals holding an accepted | |
| 10 | + * grant in the `_desktop_mode_folder_shares` table (role grants | |
| 11 | + * additionally require a per-user accepted row in the decisions | |
| 12 | + * table). The folders row's `share_meta` column is | |
| 13 | + * diagnostic-only and is never consulted for visibility. | |
| 14 | + * - `all` — every openstation user on the site. | |
| 12 | 15 | * |
| 13 | - * Hooked at priority 5 on `desktop_mode_files_visible_folders` | |
| 16 | + * Hooked at priority 5 on `openstation_files_visible_folders` | |
| 14 | 17 | * so plugins layering custom share modes (registered via |
| 15 | - * `desktop_mode_files_share_modes`) can run later in the chain | |
| 18 | + * `openstation_files_share_modes`) can run later in the chain | |
| 16 | 19 | * without competing for the early slot. |
| 17 | 20 | * |
| 18 | - * @package WPDesktopMode | |
| 19 | - * @since 0.9.0 | |
| 21 | + * @package OpenStation | |
| 20 | 22 | */ |
| 21 | 23 | |
| 22 | 24 | defined( 'ABSPATH' ) || exit; |
| 23 | 25 | |
| @@ -24,15 +26,13 @@ | ||
| 24 | 26 | /** |
| 25 | 27 | * Filter callback that augments the owner-only list with folders |
| 26 | 28 | * the viewer can see by virtue of a non-private share mode. |
| 27 | 29 | * |
| 28 | - * @since 0.9.0 | |
| 29 | - * | |
| 30 | 30 | * @param array $owned Owner-only folders (default from the store). |
| 31 | 31 | * @param int $user_id Viewer. |
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | -function desktop_mode_files_compute_visible_folders( $owned, $user_id ) { | |
| 34 | +function openstation_files_compute_visible_folders( $owned, $user_id ) { | |
| 35 | 35 | global $wpdb; |
| 36 | 36 | $user_id = (int) $user_id; |
| 37 | 37 | if ( $user_id <= 0 ) { |
| 38 | 38 | return is_array( $owned ) ? $owned : array(); |
| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | if ( $user_id <= 0 ) { |
| 38 | 38 | return is_array( $owned ) ? $owned : array(); |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - $tables = desktop_mode_files_table_names(); | |
| 41 | + $tables = openstation_files_table_names(); | |
| 42 | 42 | $user = get_userdata( $user_id ); |
| 43 | 43 | $roles = $user ? array_values( (array) $user->roles ) : array(); |
| 44 | 44 | |
| 45 | 45 | // Source 1 — `share_mode='all'`. Pull straight from the folders |
| @@ -80,9 +80,9 @@ | ||
| 80 | 80 | // invites (we don't flip a role share to 'accepted' on behalf of |
| 81 | 81 | // every member of the role — that would be a "first to click |
| 82 | 82 | // decides for all" bug). The per-user acceptance lives in the |
| 83 | 83 | // decisions table, mirroring the resolution logic in |
| 84 | - // `desktop_mode_folder_share_user_capability`. | |
| 84 | + // `openstation_folder_share_user_capability`. | |
| 85 | 85 | // |
| 86 | 86 | // Without this join the role recipient could see the folder via |
| 87 | 87 | // REST `list_placements` (which routes through |
| 88 | 88 | // `_user_capability`, which DOES consult decisions) but their |
| @@ -119,33 +119,31 @@ | ||
| 119 | 119 | foreach ( $visible as $row ) { |
| 120 | 120 | $seen_ids[ (int) $row['id'] ] = true; |
| 121 | 121 | } |
| 122 | 122 | foreach ( array_merge( (array) $all_rows, (array) $share_rows ) as $raw ) { |
| 123 | - $row = desktop_mode_files_normalize_folder_row( $raw ); | |
| 123 | + $row = openstation_files_normalize_folder_row( $raw ); | |
| 124 | 124 | $id = (int) $row['id']; |
| 125 | 125 | if ( isset( $seen_ids[ $id ] ) ) { |
| 126 | 126 | continue; |
| 127 | 127 | } |
| 128 | - if ( desktop_mode_files_user_can_see_folder( $row, $user_id, $roles ) ) { | |
| 129 | - $visible[] = $row; | |
| 128 | + if ( openstation_files_user_can_see_folder( $row, $user_id, $roles ) ) { | |
| 129 | + $visible[] = $row; | |
| 130 | 130 | $seen_ids[ $id ] = true; |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | return $visible; |
| 134 | 134 | } |
| 135 | -add_filter( 'desktop_mode_files_visible_folders', 'desktop_mode_files_compute_visible_folders', 5, 2 ); | |
| 135 | +add_filter( 'openstation_files_visible_folders', 'openstation_files_compute_visible_folders', 5, 2 ); | |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Whether the viewer's identity satisfies a folder's share rules. |
| 139 | 139 | * |
| 140 | - * @since 0.9.0 | |
| 141 | - * | |
| 142 | 140 | * @param array $folder Normalized folder row. |
| 143 | 141 | * @param int $user_id Viewer. |
| 144 | 142 | * @param string[] $user_roles Viewer's roles. |
| 145 | 143 | * @return bool |
| 146 | 144 | */ |
| 147 | -function desktop_mode_files_user_can_see_folder( $folder, $user_id, $user_roles ) { | |
| 145 | +function openstation_files_user_can_see_folder( $folder, $user_id, $user_roles ) { | |
| 148 | 146 | $mode = (string) $folder['share_mode']; |
| 149 | 147 | |
| 150 | 148 | // Owner always sees the folder. |
| 151 | 149 | if ( (int) $folder['owner_id'] === (int) $user_id ) { |
| @@ -159,9 +157,9 @@ | ||
| 159 | 157 | // drafts had a fallback that silently re-granted access |
| 160 | 158 | // to revoked recipients; reviewer caught the |
| 161 | 159 | // revocation-bypass and we dropped the fallback before |
| 162 | 160 | // the feature shipped.) |
| 163 | - $cap = desktop_mode_folder_share_user_capability( (int) $folder['id'], (int) $user_id ); | |
| 161 | + $cap = openstation_folder_share_user_capability( (int) $folder['id'], (int) $user_id ); | |
| 164 | 162 | $can = 'none' !== $cap; |
| 165 | 163 | } |
| 166 | 164 | |
| 167 | 165 | /** |
| @@ -168,13 +166,11 @@ | ||
| 168 | 166 | * Filter the per-folder visibility decision. Plugins layering |
| 169 | 167 | * custom share modes (e.g. 'team', 'workspace') can compute |
| 170 | 168 | * `$can` here. |
| 171 | 169 | * |
| 172 | - * @since 0.9.0 | |
| 173 | - * | |
| 174 | 170 | * @param bool $can Default decision. |
| 175 | 171 | * @param array $folder Folder row. |
| 176 | 172 | * @param int $user_id Viewer. |
| 177 | 173 | * @param string[] $roles Viewer's roles. |
| 178 | 174 | */ |
| 179 | - return (bool) apply_filters( 'desktop_mode_files_user_can_see_folder', $can, $folder, $user_id, $user_roles ); | |
| 175 | + return (bool) apply_filters( 'openstation_files_user_can_see_folder', $can, $folder, $user_id, $user_roles ); | |
| 180 | 176 | } |