Repository: inventree/InvenTree

Issue:
EMail host is required for SSO self registration
### Please verify that this bug has NOT been raised before.

- [X] I checked and didn't find a similar issue

### Describe the bug*

The [CustomSocialAccountAdapter](https://github.com/inventree/InvenTree/blob/c28c991591c9bd2c29be4c0046d500e3271feda2/InvenTree/InvenTree/forms.py#LL289C16-L289C16) extends the RegistratonMixin which overrides the `is_open_for_signup` method. In my opinion, the [check](https://github.com/inventree/InvenTree/blob/c28c991591c9bd2c29be4c0046d500e3271feda2/InvenTree/InvenTree/forms.py#L217) performed in the function should not be the intended behavior for Social Accounts.

### Steps to Reproduce

1. Configure a social account for your inventree instance
2. Make sure no email host is configured
3. Try to sign in for the first time with a social account user and experience the "Sign in Closed" page.

### Expected behaviour

In my opinion, it should not be required to configure an email host in order to enable SocialAccount self registration.

My personal use case:
I am currently running InvenTree on my local machine and played around with the OpenID config. It took me forever to figure out why my social login did not work. I finally solved it by specifying a dummy value `INVENTREE_EMAIL_HOST = localhost`.

Do you think it is possible to disable the email host check if a social account is used?

### Deployment Method

- [X] Docker
- [ ] Bare metal

### Version Information

Master branch

### Relevant log output

_No response_


Discussion:
This is on purpose, you can lock yourself out of your instance if you have no way to reset your password. For that, you need an email provider.
I understand that this is the case for a instance using the integrated authentication, but this should not be an issue with Social Accounts as there is always the provider of the corresponding social account which is responsible for resetting the password. Also, as an admin I always have the ability to generate a new admin account using the CLI if the social account provider was misconfigured and must be changed
Providers go down and ppl. lose access to external accounts for a multitude of reasons. If you only have 5 users on your private instance you can go into the CLI and change stuff easily. Once you deploy in a larger org those kinds of access get harder because of compliance and security concerns.
I would really like to not remove the mail requirement - InvenTree is unable to communicate reset instructions with the user once they lock themself out. We can add some warning to the console output if you find it confusing.
> We can add some warning to the console output if you find it confusing.

Additionally, there should be some obvious message in the UI if a certain feature is disabled because of some other setting (i.e. mail not being setup)
In general I agree that we should not remove the email requirement here. We can improve the docs around this, but the email will stay
> Once you deploy in a larger org those kinds of access get harder because of compliance and security concerns.

I did not think about large scale deployments, I agree on your point keeping the mail

> We can add some warning

> Additionally, there should be some obvious message in the UI

That would be great! Do you want me to create a PR adding the console warning and documentation, or do you want to implement it yourself? Not sure if I'd be able to figure out and display the error in the UI though, this would require me to take another look.
A contribution would be wonderful @p-fruck

I think the best place to start would be in the global settings [here](https://github.com/inventree/InvenTree/blob/master/InvenTree/templates/InvenTree/settings/login.html) - there are also warnings there (like [this](https://github.com/inventree/InvenTree/blob/58e9065b41958fbf1e95f380d5820ad4083d661e/InvenTree/templates/InvenTree/settings/login.html#L15-L17)). You can also add a warning in form of a print statement in the `settings.py` where we check for email settings.
This issue seems stale. Please react to show this is still important.
This issue seems stale. Please react to show this is still important.
Not stale bot.

@p-fruck would you be willing to submit a PR against this?
@SchrodingersGat I kind of lost track on this. I'd be willing to submit a PR, but I won't have time to look into this until mid september.

Resolving patch:
diff --git a/InvenTree/InvenTree/forms.py b/InvenTree/InvenTree/forms.py
--- a/InvenTree/InvenTree/forms.py
+++ b/InvenTree/InvenTree/forms.py
@@ -228,7 +228,12 @@ def clean(self):
 
 def registration_enabled():
     """Determine whether user registration is enabled."""
-    return settings.EMAIL_HOST and (InvenTreeSetting.get_setting('LOGIN_ENABLE_REG') or InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO_REG'))
+    if InvenTreeSetting.get_setting('LOGIN_ENABLE_REG') or InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO_REG'):
+        if settings.EMAIL_HOST:
+            return True
+        else:
+            logger.error("Registration cannot be enabled, because EMAIL_HOST is not configured.")
+    return False
 
 
 class RegistratonMixin:


Test patch: