-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Add creator-owned pad settings defaults #7545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JohnMcLear
merged 7 commits into
ether:develop
from
JohnMcLear:feat-pad-vs-user-settings
Apr 19, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e9b2d94
Add creator-owned pad settings defaults
JohnMcLear 7479fac
Refine pad settings layout
JohnMcLear 97a6063
Fix settings popup heading and width
JohnMcLear 30175ae
Explain enforced user settings
JohnMcLear 8f8ba9f
Cover creator override flow
JohnMcLear 5806fd1
Let creators bypass enforced settings
JohnMcLear 3220456
Address pad settings follow-ups
JohnMcLear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ import {RateLimiterMemory} from 'rate-limiter-flexible'; | |
| import {ChangesetRequest, PadUserInfo, SocketClientRequest} from "../types/SocketClientRequest"; | ||
| import {APool, AText, PadAuthor, PadType} from "../types/PadType"; | ||
| import {ChangeSet} from "../types/ChangeSet"; | ||
| import {ChatMessageMessage, ClientReadyMessage, ClientSaveRevisionMessage, ClientSuggestUserName, ClientUserChangesMessage, ClientVarMessage, CustomMessage, PadDeleteMessage, UserNewInfoMessage} from "../../static/js/types/SocketIOMessage"; | ||
| import {ChatMessageMessage, ClientReadyMessage, ClientSaveRevisionMessage, ClientSuggestUserName, ClientUserChangesMessage, ClientVarMessage, CustomMessage, PadDeleteMessage, PadOptionsMessage, UserNewInfoMessage} from "../../static/js/types/SocketIOMessage"; | ||
| import {Builder} from "../../static/js/Builder"; | ||
| const webaccess = require('../hooks/express/webaccess'); | ||
| const { checkValidRev } = require('../utils/checkValidRev'); | ||
|
|
@@ -263,6 +263,41 @@ const handlePadDelete = async (socket: any, padDeleteMessage: PadDeleteMessage) | |
| } | ||
| } | ||
|
|
||
| const isPadCreator = async (pad: any, authorId: string) => authorId === await pad.getRevisionAuthor(0); | ||
|
|
||
| const handlePadOptionsMessage = async ( | ||
| socket: any, message: PadOptionsMessage & {data: {payload: PadOptionsMessage}}) => { | ||
| const session = sessioninfos[socket.id]; | ||
| if (!session || !session.author || !session.padId) throw new Error('session not ready'); | ||
| if (!settings.enablePadWideSettings) return; | ||
| if (!await padManager.doesPadExist(session.padId)) { | ||
| messageLogger.warn(`Ignoring padoptions for missing pad ${session.padId}`); | ||
| return; | ||
| } | ||
| const pad = await padManager.getPad(session.padId, null, session.author); | ||
| if (!await isPadCreator(pad, session.author)) { | ||
| socket.emit('shout', { | ||
| type: 'COLLABROOM', | ||
| data: { | ||
| type: 'shoutMessage', | ||
| payload: { | ||
| message: { | ||
| message: 'Only the pad creator can change pad settings', | ||
| sticky: false, | ||
| }, | ||
| timestamp: Date.now(), | ||
| }, | ||
| }, | ||
| }); | ||
| return; | ||
| } | ||
| pad.setPadSettings(message.data.payload.options); | ||
| await pad.saveToDatabase(); | ||
| _getRoomSockets(session.padId).forEach((socket) => { | ||
| socket.emit('message', message); | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * Handles a message from a user | ||
|
|
@@ -413,6 +448,11 @@ exports.handleMessage = async (socket:any, message: ClientVarMessage) => { | |
| try { | ||
| switch (type) { | ||
| case 'suggestUserName': handleSuggestUserName(socket, message as unknown as ClientSuggestUserName); break; | ||
| case 'padoptions': | ||
| await handlePadOptionsMessage( | ||
| socket, | ||
| message as unknown as PadOptionsMessage & {data: {payload: PadOptionsMessage}}); | ||
| break; | ||
| default: throw new Error('unknown message type'); | ||
| } | ||
| } catch (err) { | ||
|
|
@@ -883,8 +923,13 @@ const handleClientReady = async (socket:any, message: ClientReadyMessage) => { | |
| ]); | ||
| ({colorId: authorColorId, name: authorName} = await authorManager.getAuthor(sessionInfo.author)); | ||
|
|
||
| const padExisted = await padManager.doesPadExist(sessionInfo.padId); | ||
| // load the pad-object from the database | ||
| const pad = await padManager.getPad(sessionInfo.padId, null, sessionInfo.author); | ||
| if (settings.enablePadWideSettings && !padExisted && message.padSettingsDefaults) { | ||
| pad.setPadSettings(message.padSettingsDefaults); | ||
| await pad.saveToDatabase(); | ||
| } | ||
|
|
||
| // these db requests all need the pad object (timestamp of latest revision, author data) | ||
| const authors = pad.getAllAuthors(); | ||
|
|
@@ -1025,6 +1070,8 @@ const handleClientReady = async (socket:any, message: ClientReadyMessage) => { | |
|
|
||
| // Warning: never ever send sessionInfo.padId to the client. If the client is read only you | ||
| // would open a security hole 1 swedish mile wide... | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) Great comment |
||
| const canEditPadSettings = settings.enablePadWideSettings && | ||
| !sessionInfo.readonly && await isPadCreator(pad, sessionInfo.author); | ||
| const clientVars:MapArrayType<any> = { | ||
| skinName: settings.skinName, | ||
| skinVariants: settings.skinVariants, | ||
|
|
@@ -1033,9 +1080,10 @@ const handleClientReady = async (socket:any, message: ClientReadyMessage) => { | |
| maxRevisions: 100, | ||
| }, | ||
| enableDarkMode: settings.enableDarkMode, | ||
| enablePadWideSettings: settings.enablePadWideSettings, | ||
| automaticReconnectionTimeout: settings.automaticReconnectionTimeout, | ||
| initialRevisionList: [], | ||
| initialOptions: {}, | ||
| initialOptions: pad.getPadSettings(), | ||
| savedRevisions: pad.getSavedRevisions(), | ||
| collab_client_vars: { | ||
| initialAttributedText: atext, | ||
|
|
@@ -1060,6 +1108,7 @@ const handleClientReady = async (socket:any, message: ClientReadyMessage) => { | |
| numConnectedUsers: roomSockets.length + 1, // +1 for this user (not yet in room) | ||
| readOnlyId: sessionInfo.readOnlyPadId, | ||
| readonly: sessionInfo.readonly, | ||
| canEditPadSettings, | ||
| serverTimestamp: Date.now(), | ||
| sessionRefreshInterval: settings.cookie.sessionRefreshInterval, | ||
| userId: sessionInfo.author, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.