saltcorn-samba 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/index.js +60 -12
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ All notable changes to `saltcorn-samba` are documented here.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [0.3.7] – 2026-07-05
8
+
9
+ ### Fixed
10
+ - **„Only admins can test the connection.“ fälschlicherweise gemeldet.**
11
+ Die Admin-Prüfung in `POST /sambatest` verglich `req.user.role_id` mit
12
+ strikter Gleichheit gegen die Zahl `1`. Saltcorn liefert `role_id` je
13
+ nach Session-Serialisierung aber sowohl als Number wie auch als String
14
+ aus, weshalb `"1" !== 1` den Test blockierte. Die Prüfung akzeptiert
15
+ jetzt beide Formen (`Number(rid) === 1 || String(rid) === "1"`) und
16
+ liest den User zusätzlich aus `req.session.passport.user`, falls
17
+ `req.user` von einer noch nicht deserialisierten Session leer ist.
18
+ Vgl. [saltcorn utils.ts isAdminOrHasConfigMinRole](https://github.com/saltcorn/saltcorn/blob/master/packages/server/routes/utils.ts).
19
+ - Auch der zentrale `roleOf(req)`-Helper (Lese-/Schreibrouten) toleriert
20
+ jetzt String-Rollen und Session-Fallback.
21
+
22
+ ### Changed
23
+ - Bei fehlender Admin-Erkennung liefert `/sambatest` jetzt ein
24
+ `debug`-Objekt mit `has_req_user`, `has_session`, `role_id_seen`,
25
+ `role_id_type`, `email`, `user_id`. Der Test-Button zeigt diese
26
+ Diagnose in einem aufklappbaren „Session-Diagnose“-Panel – damit
27
+ wird sofort sichtbar, was Saltcorn dem Plugin zum Benutzer mitgibt.
28
+
7
29
  ## [0.3.6] – 2026-07-05
8
30
 
9
31
  ### Fixed
package/index.js CHANGED
@@ -156,20 +156,31 @@ window.sambaTestConn = async function(btn) {
156
156
  '</div>';
157
157
  } else {
158
158
  var a = data && data.attempted || {};
159
+ var dbg = data && data.debug;
160
+ var titleForCode = (data && data.code === 'NOT_ADMIN')
161
+ ? '✗ Nicht als Administrator erkannt'
162
+ : '✗ Verbindung fehlgeschlagen';
159
163
  out.innerHTML =
160
164
  '<div class="alert alert-danger">' +
161
- '<b>✗ Verbindung fehlgeschlagen</b><br>' +
165
+ '<b>' + titleForCode + '</b><br>' +
162
166
  'Fehler: <code>' + String(data && data.error || 'Unbekannt').replace(/[<>&]/g,'?') + '</code>' +
163
167
  (data && data.code ? ' <span class="text-muted">(' + data.code + ')</span>' : '') + '<br>' +
164
168
  (data && data.hint ? '<div style="margin-top:.4rem"><b>Hinweis:</b> ' + String(data.hint).replace(/[<>&]/g,'?') + '</div>' : '') +
165
- '<details style="margin-top:.4rem"><summary>Versuchte Verbindungsdaten</summary>' +
166
- '<table class="table table-sm" style="margin-top:.4rem">' +
167
- '<tr><td>Server</td><td><code>' + (a.server||'') + ':' + (a.port||'') + '</code></td></tr>' +
168
- '<tr><td>Share</td><td><code>' + (a.share||'') + '</code></td></tr>' +
169
- '<tr><td>Basispfad</td><td><code>' + (a.base_path||'') + '</code></td></tr>' +
170
- '<tr><td>Domäne</td><td><code>' + (a.domain||'') + '</code></td></tr>' +
171
- '<tr><td>Benutzer</td><td><code>' + (a.username||'') + '</code></td></tr>' +
172
- '</table></details>' +
169
+ (a.server ? (
170
+ '<details style="margin-top:.4rem"><summary>Versuchte Verbindungsdaten</summary>' +
171
+ '<table class="table table-sm" style="margin-top:.4rem">' +
172
+ '<tr><td>Server</td><td><code>' + (a.server||'') + ':' + (a.port||'') + '</code></td></tr>' +
173
+ '<tr><td>Share</td><td><code>' + (a.share||'') + '</code></td></tr>' +
174
+ '<tr><td>Basispfad</td><td><code>' + (a.base_path||'') + '</code></td></tr>' +
175
+ '<tr><td>Domäne</td><td><code>' + (a.domain||'') + '</code></td></tr>' +
176
+ '<tr><td>Benutzer</td><td><code>' + (a.username||'') + '</code></td></tr>' +
177
+ '</table></details>'
178
+ ) : '') +
179
+ (dbg ? (
180
+ '<details style="margin-top:.4rem"><summary>Session-Diagnose</summary>' +
181
+ '<pre style="margin-top:.4rem">' + JSON.stringify(dbg, null, 2) + '</pre>' +
182
+ '</details>'
183
+ ) : '') +
173
184
  '</div>';
174
185
  }
175
186
  } catch (e) {
@@ -371,7 +382,14 @@ function getConfig() {
371
382
  }
372
383
 
373
384
  function roleOf(req) {
374
- return (req && req.user && req.user.role_id) || 100;
385
+ const u =
386
+ (req && req.user) ||
387
+ (req && req.session && req.session.passport && req.session.passport.user) ||
388
+ null;
389
+ if (!u) return 100;
390
+ const rid = u.role_id !== undefined ? u.role_id : u.roleId;
391
+ const n = Number(rid);
392
+ return Number.isFinite(n) && n > 0 ? n : 100;
375
393
  }
376
394
 
377
395
  function canRead(req, cfg) {
@@ -588,8 +606,38 @@ code{background:#f4f4f4;padding:2px 6px;border-radius:3px;word-break:break-all}<
588
606
  // save-workflow or when a stricter CSRF policy is applied.
589
607
  noCsrf: true,
590
608
  callback: async ({ req, res }) => {
591
- if (roleOf(req) !== 1) {
592
- return jsonError(res, 403, "Only admins can test the connection.");
609
+ // Admin gate be permissive about how Saltcorn represents the role:
610
+ // • req.user.role_id may be a Number (1) or a String ("1") depending
611
+ // on how the session was serialised.
612
+ // • In some tenant/session configs req.user is populated later; we
613
+ // also check req.session.passport.user as a fallback.
614
+ const u =
615
+ (req && req.user) ||
616
+ (req && req.session && req.session.passport && req.session.passport.user) ||
617
+ null;
618
+ const rid = u && (u.role_id !== undefined ? u.role_id : u.roleId);
619
+ const isAdmin = u && (Number(rid) === 1 || String(rid) === "1");
620
+ if (!isAdmin) {
621
+ return res.status(403).json({
622
+ ok: false,
623
+ error: "Only admins can test the connection.",
624
+ code: "NOT_ADMIN",
625
+ hint:
626
+ "Der Server hat Sie für diese Anfrage nicht als Administrator erkannt. " +
627
+ "Mögliche Ursachen: (1) Sie sind in einem anderen Tab abgemeldet worden, " +
628
+ "(2) die Konfigurations-Seite wurde in einem privaten/Inkognito-Fenster " +
629
+ "geöffnet ohne gültige Session, (3) Saltcorn läuft hinter einem Reverse-" +
630
+ "Proxy, der Cookies nicht weiterreicht. Bitte im selben Fenster neu " +
631
+ "anmelden und die Seite neu laden.",
632
+ debug: {
633
+ has_req_user: !!(req && req.user),
634
+ has_session: !!(req && req.session),
635
+ role_id_seen: rid === undefined ? null : String(rid),
636
+ role_id_type: rid === undefined ? "undefined" : typeof rid,
637
+ email: (u && u.email) || null,
638
+ user_id: (u && u.id) || null,
639
+ },
640
+ });
593
641
  }
594
642
  // Accept both JSON and URL-encoded bodies. express.json and
595
643
  // express.urlencoded are both installed globally by Saltcorn.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saltcorn-samba",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "Saltcorn plugin: browse, upload, rename and delete files on a Samba/CIFS share. File-manager view, directory tree, inline PDF viewer, external-app open (smb://).",
5
5
  "main": "index.js",
6
6
  "scripts": {