Skip to content
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

Adds "invite_only" disable_registration config option #1841

Merged
merged 7 commits into from
May 3, 2022

Conversation

Vigasaurus
Copy link
Contributor

@Vigasaurus Vigasaurus commented Apr 19, 2022

Changes

Allows for the DISABLE_REGISTRATION config flag to support three states.
false => registration is allowed as normal, for both normal users and invited users
invite_only => registration is allowed for those with an invite link, but prevented for normal users
true => registration is entirely disabled, regardless of invite status

@jesperordrup - after taking a look, this honestly was too trivial to implement for me to actually expect or accept a bounty for it (assuming it is good enough in its current state).

I'll add the docs + changelog entry after confirming the implementation.

Tests

  • Automated tests have been added updated

Changelog

  • Entry has been added to changelog

Documentation

  • Docs have been updated

Dark mode

  • This PR does not change the UI

@bundlemon
Copy link

bundlemon bot commented Apr 19, 2022

BundleMon

Unchanged files (7)
Status Path Size Limits
static/css/app.css
515.1KB -
static/js/dashboard.js
286.81KB -
static/js/app.js
12.13KB -
static/js/embed.host.js
5.58KB -
static/js/embed.content.js
5.06KB -
tracker/js/plausible.js
751B -
static/js/applyTheme.js
314B -

No change in files bundle size

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

Copy link
Contributor

@ukutaht ukutaht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Let's make the field a bit more restrictive so a random value wouldn't be accepted. But then we can merge indeed

config/runtime.exs Show resolved Hide resolved
@jesperordrup
Copy link

@jesperordrup - after taking a look, this honestly was too trivial to implement for me to actually expect or accept a bounty for it (assuming it is good enough in its current state).

@Vigasaurus Wow! That is generous. let me know if something changes.

Thank you for the speedy update. Lets hope theres a release in near future.

@Vigasaurus Vigasaurus changed the title Adds "allow-invites" disable_registration config option Adds "invite_only" disable_registration config option Apr 20, 2022
@ukutaht ukutaht merged commit b7b69c6 into plausible:master May 3, 2022
@ukutaht
Copy link
Contributor

ukutaht commented May 3, 2022

Thanks @Vigasaurus !

@jesperordrup this will be part of the next self-hosted release. Coming soon.

@jesperordrup
Copy link

"coming soon" is of course a matter of interpretation. Initially I held my breath but I found that it wasn't possible 👍😂

@ukutaht
Copy link
Contributor

ukutaht commented May 30, 2022

I'm sorry @jesperordrup, I'm having to deal with some unexpected health issues. The release is coming as soon as possible.

@jesperordrup
Copy link

Oh. Get well and forget my "funny" comment Pls

ukutaht pushed a commit that referenced this pull request May 30, 2022
* Adds tri-state disable_registration config

* Formatting

* Changes variable back to atom

* Changelog

* Uses atoms correctly :/

* Swaps to a more fitting value

* Formatting
@jesperordrup
Copy link

Hi all. Hope that all is well. Any news?

@metmarkosaric
Copy link
Contributor

hi @jesperordrup! no news at the moment. this is on our self-hosted roadmap but we have no timelines that we can promise. we have limited resources and the self-hosted release depends on the free capacity of our developers. as soon as there's news we will post an update, thanks!

@jesperordrup
Copy link

no news at the moment. this is on our self-hosted roadmap but we have no timelines that we can promise. we have limited resources and the self-hosted release depends on the free capacity of our developers. as soon as there's news we will post an update, thanks!

I know, all fine. I'm aware of the setup. But in the end, it's also about if the setup works for me. This is not your concern, of course. But I of course have to deal with the consequences. Not complaining in any way - as I say - I'm aware of the setup. Just asking because initially it was "coming soon". So I'd thought I just ask.

@metmarkosaric
Copy link
Contributor

our goal is two releases per year. last version was released less than 5 months ago. we're hoping for the next one to be done in the next month or so but no guarantees or promises. we have a goal of twice per year and we hope to make it every time but things are unpredictable as we have limited resources. we will publish the release as soon as it's ready.

@jesperordrup
Copy link

jesperordrup commented Aug 6, 2022

I just tested the the invite_only feature using docker:

changed the image referenced in the docker-compose.yml file to:


  plausible:
    image: plausible/analytics:master

and updated plausible-conf.env

DISABLE_REGISTRATION=invite_only

Now I can Invite but when I click on the invitation link im taken to the login screen. Is this where its at or has I missed something`?

Clicking the link http://localhost:8000/register/invitation/wIus542ERPZMPyFDQkhCK
results in a 302 redirect with the following response headers:

image

@ruslandoga
Copy link
Contributor

@jesperordrup hi! Could you please try out the new release candidate #2324 and check if it works better there?

@jesperordrup
Copy link

jesperordrup commented Dec 14, 2022

I just tested the new release.

What I did

  • Updated DISABLE_REGISTRATION=invite_only
  • restarted
  • opened a website configuration
  • invited a new user and set to viewer
  • received the email
  • clicked the link and opened page that allows me to login

Error
shows login dialog

image

What should have happened
show dialog to proceed with the invitation (register)

Recap of what the purpose of invite_only is

  • Enable the possibility for an admin to add a website and invite new users as admins or viewers to this website.
  • Only allow anyone with an invitation to create an account and access a website

@ruslandoga
Copy link
Contributor

ruslandoga commented Dec 14, 2022

👋 @jesperordrup

I'm having trouble reproducing this error on my instance...

Screenshot 2022-12-14 at 20 04 47

Can you please check the database to include the invitation, check its timestamp? Can you please post the URL that was sent in the email? Are there any errors in the logs / console?

You can also try connecting to your running app with

$ docker compose exec -ti plausible bin/plausible remote

and then listing the invitations there (please post them here)

iex> Plausible.Repo.all Plausible.Auth.Invitation
[
  %Plausible.Auth.Invitation{
    __meta__: #Ecto.Schema.Metadata<:loaded, "invitations">,
    email: "zlobushka666@gmail.com",
    id: 2,
    inserted_at: ~N[2022-12-14 12:59:09],
    invitation_id: "kWkcqBGrobbKT0r9aef1x",
    inviter: #Ecto.Association.NotLoaded<association :inviter is not loaded>,
    inviter_id: 1,
    role: :viewer,
    site: #Ecto.Association.NotLoaded<association :site is not loaded>,
    site_id: 2,
    updated_at: ~N[2022-12-14 12:59:09]
  }
]

I'm also interested in what this command returns

iex> Application.get_env :plausible, :selfhost
[enable_email_verification: false, disable_registration: :invite_only]

@jesperordrup
Copy link

thanks @ruslandoga.

This is running on a coolify setup using:
image

Plausible has been updated with 1.51 (its not a new install)

The invite url looks like this:
https://hostname/register/invitation/7TbLQUYS2Kxf24PIgzsqZ

When hitting it I get a 302 to

https://hostname/login

When I create the invite the log updates with:

2022-12-15T09:21:16.678742662Z
2022-12-15T09:21:16.678728204Z Reason: 'Option {verify, verify_peer} and cacertfile/cacerts is missing'
2022-12-15T09:21:16.678667782Z 09:21:16.678 request_id=FzDtBxrXLRVr_cMAAcMB [warning] Description: 'Authenticity is not established by certificate path validation'

When I click the invite url, nothing happens in log or browser console (other than redirect to login)

@ruslandoga
Copy link
Contributor

ruslandoga commented Dec 15, 2022

I'm not familiar with Coolify, unfortunately. Does it allow you to connect to the running plausible container the way I showed above?

Since it's a not a docker compose setup, can you verify the image is indeed updated and the container is running the new image version, v1.5.1?

@jesperordrup
Copy link

I've tried

$ docker exec -ti plausible bin/plausible remote

And ran Plausible.Repo.all Plausible.Auth.Invitation

  %Plausible.Auth.Invitation{
    __meta__: #Ecto.Schema.Metadata<:loaded, "invitations">,
    email: "p@umakers.dk",
    id: 17,
    inserted_at: ~N[2022-12-15 09:13:05],
    invitation_id: "7TbLQUYS2Kxf24PIgzsqZ",
    inviter: #Ecto.Association.NotLoaded<association :inviter is not loaded>,
    inviter_id: 1,
    role: :admin,
    site: #Ecto.Association.NotLoaded<association :site is not loaded>,
    site_id: 13,
    updated_at: ~N[2022-12-15 09:13:05]
  },
  %Plausible.Auth.Invitation{
    __meta__: #Ecto.Schema.Metadata<:loaded, "invitations">,
    email: "p2@umakers.dk",
    id: 18,
    inserted_at: ~N[2022-12-15 09:21:16],
    invitation_id: "W1_yCm4y7j_mf5v3QpsA_",
    inviter: #Ecto.Association.NotLoaded<association :inviter is not loaded>,
    inviter_id: 1,
    role: :admin,
    site: #Ecto.Association.NotLoaded<association :site is not loaded>,
    site_id: 13,
    updated_at: ~N[2022-12-15 09:21:16]
  }
]

Also this one
iex(plausible@bac8ad241df6)2> Application.get_env :plausible, :selfhost

Result (which clearly indicates a problem 🥇 )
[enable_email_verification: false, disable_registration: true]

Wonder why disable_registration is true. In Coolify I've added this (and redeployed)

image

@ruslandoga
Copy link
Contributor

ruslandoga commented Dec 15, 2022

I'd try adding some dummy env vars and checking them from the running container with System.get_env.

iex> System.get_env("DUMMY")
"value"

If they do show up, then I'd try changing one of them and checking the change with System.get_env again.

iex> System.get_env("DUMMY")
"updated_value"

If new env vars don't show up or are not updated, the issue is somewhere with Coolify.

@jesperordrup
Copy link

jesperordrup commented Dec 15, 2022

I tested some more:

When I enter the container and do a
System.get_env("DISABLE_REGISTRATION")

It always returns "true". Any changes I make to the env var in coolify is ignored.

image

I then added a new environment variable "FISK" to the service

System.get_env("FISK")

Any changes to this IS updated without problem.

@ruslandoga
Copy link
Contributor

ruslandoga commented Dec 15, 2022

Could there be multiple places where this env var is set? I see "Secrets" in your screenshot, is there a place for non-secret env vars maybe?

Could you try a fresh installation?

@jesperordrup
Copy link

Solved. You're right! Coolify is overriding. They have added direct support for DISABLE_REGISTRATION which does not include invite_only - I've notified Coolify.

Im installing in another setup.

Thanks for your help

@jesperordrup
Copy link

Aaaand just finished testing on a local docker. Its working great !!! Assuming that it sends out the invite (i just grabbed the invitation id from ( Plausible.Repo.all Plausible.Auth.Invitation ) and composed the invite url

/registration/invitation/MWHzC0_f1f_dNplXQxQAZ

And it worked!

Awesome - I can setup a server. Yay :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants