@phenomlab Thanks! I did not know this was available. I'll have a look to see if it fits my needs.
magnusvhendin
Posts
-
How to show custom text when user is deleted? -
How to show custom text when user is deleted?So when you delete a user (not the content) the name defaults to "Guest". How would I change this to something else? My forum is (by plugin) locked, so there are no such thing as guests.
I would like to replace it with something like "Previous user" instead and on a global scope. I need it to show the same in chats, posts and everything else connected.
I could of course use a list of hooks and write custom functions to change the name to a custom language file string, but it would be more convenient to catch it once.
Any ideas?
-
Redirect to login@baris That's it. Worked like a charm. Thanks!
-
Redirect to loginI also tried to use the helper function notAllowed, but I get the same result. Redirects to
/login
but get errors in the log that data is undefined and there is nocatch()
.library.checkLoginStatus = async (data) => { if (data.req.loggedIn || allowedUrls(data.req.url) ) { return data; } return Helpers.notAllowed(data.req, data.res); };
-
Redirect to loginSeems like reverting to callbacks resolves it. I really wanted this to work with async/await, since callbacks will sooner or later be phased out I guess.
library.checkLoginStatus = (data, callback) => { if (data.req.loggedIn || allowedUrls(data.req.url) ) { callback(null, data); } else { Helpers.redirect(data.res, '/login'); } };
-
Redirect to loginThough this works, it also redirects every call for assets (images, stylesheets etc). So I get a site without CSS.
Maybe another hook is more appropriate?
I also have another function that redirects to the profile page if some information is not properly filled in.
So the overarching question is not to lock people out, it's more about how to divert a user based on some conditions. For instance, we have to require the users full name, so if it's not filled out, they get redirected to their profile edit page and asked to fill it in.
EDIT: I forgot to tag you @baris.
-
Redirect to loginI have been having some issues since NodeBB went all in on async/await. I have a private forum so I need to redirect to
/login
if the visitor isn't logged in.What worked before was a library function listening to
filter:middleware.render
, and then:library.checkLoginStatus = async (data) => { if (data.req.loggedIn || allowedUrls(data.req.url) ) { return data; } return Helpers.redirect(data.res, '/login'); };
allowedUrls
is a function that just checks the requested url against a list of allowed ones (like/login
,/email/unsubscribe
and/register
).Everything worked great but now I'm upgraded to 1.16.x.
The issue I'm having is that there are other functions that tails this one listening to the same hook. So my question is if I can interrupt that flow somehow on redirect. Or maybe there's an even better solution, but it needs to be forum wide. The tailing functions get undefined passed in so everything breaks. The weird thing is that everything seems to work, and it semi silently drops the error. But I don't want a bunch of error logs cluttering things up.
I know NodeBB is meant to be open and all, but in this case I need to lock it down until someone has registered. I built this functionality when on 1.12 I think so something else might be a better option.
I'm turning to you community.
-
Difference between templateValues and templateDataYep, I see the issue. I'm not looking to push any changes. It was more out of curiosity on why there are several different names within essentially the same function.
-
Difference between templateValues and templateDataYeah, I guess my line of thinking is; why not just have
templateValues
andtemplateData
on initial render and thentemplateData
on page render? It just feels a bit confusing with these different signatures and names.So, what is
data
used for when header is rendered? Is it even used? And if not, why not just usetemplateData
on all of them with things related to their function?templateData
on header hook is to render header.
templateData
on page hook is to render page.
templateData
on footer hook is to render footer.I'm guessing there are cases where it's useful for
data
to be passed along the ride, but they're already treated as different parts, so maybe it's just easier to separate them entirely. -
Difference between templateValues and templateDataHi!
What's the difference betweentemplateValues
(tV) andtemplateData
(tD)?I know we get tD from a template hook and tV from a header hook, but we also get
data
from the header hook, which contains the dame data as in tD?Hook data object keys in the two cases:
[ 'req', 'res', 'templateValues', 'data' ]
from header hook.[ 'req', 'res', 'templateData' ]
from template hook.
So this might not be a technical question at all. I'm just wondering what the naming is meant to be. Maybe someone can shed some light on this, perhaps simple question?
For instance, if
data
in header hook is the same as tD in template hook, why is it not just called templateData instead, to avoid confusion?I guess a header hook is only fired on initial render and not when the user navigates around, as is the case with a template hook.
Also, when for
filter:middleware.renderFooter
is fired, only tV is present and notdata
? -
Hide category from feedsIs there some way to hide all topics within a category from all feeds (recent, popular, new, the digest)?
I need the topics to be accessible (and usable) to all users directly, but not searchable or showing up at random.
-
Send invite without a userThank you for the response @gotwf!
The issue is that I cannot delete an invite if I leave the inviter uid blank. I would think that an error would've been sent if this would cause problems. I have added a field in my plugin that will let admins select who will work as the inviter. in my case it's a system user, like no_reply@service...
The sender is a no-person email so that's not the issue. The issue is that the invite needs to (in the system) be sent my a user. Which doesn't make sense in my opinion. It's great if an admin sends an invite, but why prevent me from deleting an invite that doesn't have an error?
-
Send invite without a userIs it possible to send an email invitation without having a user attached to it?
I'm trying to use
User.sendInvitationEmail(uid, email)
, but if I send innull
,undefined
or0
as the uid I get no feedback that it's wrong. What I do get is, in the ACP, no ability to delete the invite.All I get is
I have a locked down forum but I'm working on a feature to automate the invitation process based on some parameters. So in the end I need to run something automagically.
The delete function used is this I guess?
-
Add server side hooks listeners in runtime?@baris That's it! Thanks a lot.
-
Add server side hooks listeners in runtime?I'm trying to figure this out. Is there a way to add a listener for a server side hook in runtime without adding it to
plugin.json
?Something like
Plugins.registerHook('filter:groups.get', myRuntimeFunc)
.The plugin I'm creating would benefit from this so the user have more control over when data should be fetched from an external API. I believe the answer will be no, but I need to ask.
-
Client script cannot be available in both main and admin?Thanks for the clarification @PitaJ! I did a lot of experimenting but I guess I didn't get the right combination. I think I never tried naming the module with its extension. That might have been it. For anyone who might be interested in the actual solution, here it is:
In file-explorer.js:
define('azure/file-explorer', ['components'], function (components) { const FileExplorer = {}; FileExplorer.init = function () { // Init stuff here }); return FileExplorer; });
In plugin.json:
"modules": { "azure/file-explorer.js": "static/lib/file-explorer.js" },
In admin.js:
define('admin/plugins/azure', ['settings', 'azure/file-explorer'], function (settings, fileExplorer) { fileExplorer.init(); });
In main.js:
$(document).ready(function () { require(['azure/file-explorer'], (fileExplorer) => { fileExplorer.init(); }); });
-
Client script cannot be available in both main and admin?Only thing that seems to work is using
define
and placing it in either scripts or acpScripts, but not in both. -
Client script cannot be available in both main and admin?@julian, I tried what you suggested and I'm not sure I made a mistake but it doesn't seem like it's accepted as a module. I tried:
"modules": { "file-explorer.js": "static/lib/file-explorer.js" },
and the require it
require(['file-explorer.js'], (fileExplorer) => {...}
,require(['file-explorer'], (fileExplorer) => {...}
andrequire('file-explorer.js', (fileExplorer) => {...}
but nothing seems to work.It's defined like this:
define('azure/file-explorer', ['components'], function (components) {...});
also tried to do
module.exports = fileExplorer
without the define part.Tried to require it with it's defined name
azure/file-explorer
, but no cigar. The fileExplorer comes out as undefined. -
Client script cannot be available in both main and admin?So I'm having an issue which I hope you, the community, can shed some light on. I'm currently building a plugin to incorporate a external storage solution on Azure (not replacing post and topic file storage).
I made a client script that I want to be able to use both in the admin panel and in the forum views. I use
define('my-thing/the-script')
and add it toplugin.json
under scripts.But I cannot require it in the admin script. Not with require or by placing it in the define function.
I tried to add it in acpScript in
plugin.json
, but then everything broke.My last attempt was to make a clone of the original script and appending it with
-admin
. So, script name, define name, everything. And it worked.So I guess my question is: Is it not possible to add the same script to both backend and frontend. They both serve the same purpose so just duplicating it doesn't really make sense.
-
Template no not being used in some environmentsThat was it. Had no idea that this was a thing. Thanks a lot @baris!