From 913631fa3e8b491714b02824258d9796cddfe7ee Mon Sep 17 00:00:00 2001 From: Miku Laitinen Date: Sun, 11 Jun 2023 15:42:07 +0300 Subject: [PATCH] [ADD] auth_oauth_signup --- auth_oauth_signup/README.rst | 90 ++++ auth_oauth_signup/__init__.py | 3 + auth_oauth_signup/__manifest__.py | 17 + auth_oauth_signup/models/__init__.py | 4 + .../models/auth_oauth_provider.py | 15 + auth_oauth_signup/models/res_users.py | 36 ++ auth_oauth_signup/readme/CONTRIBUTORS.rst | 1 + auth_oauth_signup/readme/DESCRIPTION.rst | 9 + auth_oauth_signup/readme/USAGE.rst | 2 + .../static/description/index.html | 436 ++++++++++++++++++ .../views/auth_oauth_provider_views.xml | 16 + .../odoo/addons/auth_oauth_signup | 1 + setup/auth_oauth_signup/setup.py | 6 + 13 files changed, 636 insertions(+) create mode 100644 auth_oauth_signup/README.rst create mode 100644 auth_oauth_signup/__init__.py create mode 100644 auth_oauth_signup/__manifest__.py create mode 100644 auth_oauth_signup/models/__init__.py create mode 100644 auth_oauth_signup/models/auth_oauth_provider.py create mode 100644 auth_oauth_signup/models/res_users.py create mode 100644 auth_oauth_signup/readme/CONTRIBUTORS.rst create mode 100644 auth_oauth_signup/readme/DESCRIPTION.rst create mode 100644 auth_oauth_signup/readme/USAGE.rst create mode 100644 auth_oauth_signup/static/description/index.html create mode 100644 auth_oauth_signup/views/auth_oauth_provider_views.xml create mode 120000 setup/auth_oauth_signup/odoo/addons/auth_oauth_signup create mode 100644 setup/auth_oauth_signup/setup.py diff --git a/auth_oauth_signup/README.rst b/auth_oauth_signup/README.rst new file mode 100644 index 0000000000..785e754f97 --- /dev/null +++ b/auth_oauth_signup/README.rst @@ -0,0 +1,90 @@ +============ +OAuth Signup +============ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a2177feb1b18da2333cb08d6343b0ded42c1e56909f3ff8d6cd77d1268c99e50 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--auth-lightgray.png?logo=github + :target: https://github.com/OCA/server-auth/tree/16.0/auth_oauth_signup + :alt: OCA/server-auth +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-auth-16-0/server-auth-16-0-auth_oauth_signup + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-auth&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +Enable sign up for users logging in using OAuth2 on a per-provider basis, overriding the global setting. + +Without this module, your options are: + 1. allow sign up for everyone who can access the login page + 2. import users (and provide values for `oauth_provider_id` and `oauth_uid`) before they log in for the first time. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Go to Settings -> Users & Companies -> OAuth Providers -> and click "Allow Signup" to allow sign up +for your OAuth2 provider's users. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Paja SIA + +Contributors +~~~~~~~~~~~~ + +* Miku Laitinen + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-auth `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/auth_oauth_signup/__init__.py b/auth_oauth_signup/__init__.py new file mode 100644 index 0000000000..e5d6d90fc1 --- /dev/null +++ b/auth_oauth_signup/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2023 Paja SIA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/auth_oauth_signup/__manifest__.py b/auth_oauth_signup/__manifest__.py new file mode 100644 index 0000000000..b1cd8aa08a --- /dev/null +++ b/auth_oauth_signup/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2023 Paja SIA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "OAuth Signup", + "version": "16.0.1.0.0", + "website": "https://github.com/OCA/server-auth", + "depends": [ + "auth_oauth", + ], + "author": "Paja SIA, " "Odoo Community Association (OCA)", + "license": "AGPL-3", + "summary": "Allow new OAuth2 users to sign up even when global sign up is disabled", + "category": "Authentication", + "data": [ + "views/auth_oauth_provider_views.xml", + ], +} diff --git a/auth_oauth_signup/models/__init__.py b/auth_oauth_signup/models/__init__.py new file mode 100644 index 0000000000..9a946dd37f --- /dev/null +++ b/auth_oauth_signup/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2023 Paja SIA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import auth_oauth_provider +from . import res_users diff --git a/auth_oauth_signup/models/auth_oauth_provider.py b/auth_oauth_signup/models/auth_oauth_provider.py new file mode 100644 index 0000000000..52568c5b12 --- /dev/null +++ b/auth_oauth_signup/models/auth_oauth_provider.py @@ -0,0 +1,15 @@ +# Copyright 2023 Paja SIA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import fields, models + + +class AuthOauthProvider(models.Model): + _inherit = "auth.oauth.provider" + + allow_signup = fields.Boolean( + default=False, + help=( + "When enabled, new users logging in through this provider for the first time " + "are allowed to sign up, even when the global sign up is disabled." + ), + ) diff --git a/auth_oauth_signup/models/res_users.py b/auth_oauth_signup/models/res_users.py new file mode 100644 index 0000000000..dcd470098f --- /dev/null +++ b/auth_oauth_signup/models/res_users.py @@ -0,0 +1,36 @@ +# Copyright 2023 Paja SIA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + +from odoo.addons.auth_signup.models.res_partner import SignupError + + +class ResUsers(models.Model): + _inherit = "res.users" + + @api.model + def _signup_create_user(self, values): + provider = False + oauth_fields = {"oauth_provider_id", "oauth_uid", "oauth_access_token"} + if values.keys() & oauth_fields and all( + values[oauth_field] for oauth_field in oauth_fields + ): + provider = self.env["auth.oauth.provider"].browse( + values["oauth_provider_id"] + ) + + try: + new_user = super(ResUsers, self)._signup_create_user(values) + except SignupError as e: + # Slightly dirty, but still cleaner than creating two separate modules + # for different scenarios based on whether "website" is installed or not. + # The method `_get_signup_invitation_scope` in "website" gets to run first + # (unless this module had a dependency to it) and thus never calls super, + # so overriding that method would only work if "website" wasn't installed. + if provider.allow_signup: + new_user = self._create_user_from_template(values) + else: + raise e + + return new_user diff --git a/auth_oauth_signup/readme/CONTRIBUTORS.rst b/auth_oauth_signup/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..77457b865b --- /dev/null +++ b/auth_oauth_signup/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Miku Laitinen diff --git a/auth_oauth_signup/readme/DESCRIPTION.rst b/auth_oauth_signup/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..1c46d15ae8 --- /dev/null +++ b/auth_oauth_signup/readme/DESCRIPTION.rst @@ -0,0 +1,9 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: https://www.gnu.org/licenses/agpl + :alt: License: AGPL-3 + +Enable sign up for users logging in using OAuth2 on a per-provider basis, overriding the global setting. + +Without this module, your options are: + 1. allow sign up for everyone who can access the login page + 2. import users (and provide values for `oauth_provider_id` and `oauth_uid`) before they log in for the first time. diff --git a/auth_oauth_signup/readme/USAGE.rst b/auth_oauth_signup/readme/USAGE.rst new file mode 100644 index 0000000000..e5b588950b --- /dev/null +++ b/auth_oauth_signup/readme/USAGE.rst @@ -0,0 +1,2 @@ +Go to Settings -> Users & Companies -> OAuth Providers -> and click "Allow Signup" to allow sign up +for your OAuth2 provider's users. diff --git a/auth_oauth_signup/static/description/index.html b/auth_oauth_signup/static/description/index.html new file mode 100644 index 0000000000..101af6ad3c --- /dev/null +++ b/auth_oauth_signup/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +OAuth Signup + + + +
+

OAuth Signup

+ + +

Beta License: AGPL-3 OCA/server-auth Translate me on Weblate Try me on Runboat

+License: AGPL-3 +

Enable sign up for users logging in using OAuth2 on a per-provider basis, overriding the global setting.

+
+
Without this module, your options are:
+
    +
  1. allow sign up for everyone who can access the login page
  2. +
  3. import users (and provide values for oauth_provider_id and oauth_uid) before they log in for the first time.
  4. +
+
+
+

Table of contents

+ +
+

Usage

+

Go to Settings -> Users & Companies -> OAuth Providers -> <your provider> and click “Allow Signup” to allow sign up +for your OAuth2 provider’s users.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Paja SIA
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-auth project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/auth_oauth_signup/views/auth_oauth_provider_views.xml b/auth_oauth_signup/views/auth_oauth_provider_views.xml new file mode 100644 index 0000000000..7b62daf5d1 --- /dev/null +++ b/auth_oauth_signup/views/auth_oauth_provider_views.xml @@ -0,0 +1,16 @@ + + + + + auth.oauth.provider.groups.form + auth.oauth.provider + + + + + + + + + + diff --git a/setup/auth_oauth_signup/odoo/addons/auth_oauth_signup b/setup/auth_oauth_signup/odoo/addons/auth_oauth_signup new file mode 120000 index 0000000000..11dcffdea0 --- /dev/null +++ b/setup/auth_oauth_signup/odoo/addons/auth_oauth_signup @@ -0,0 +1 @@ +../../../../auth_oauth_signup \ No newline at end of file diff --git a/setup/auth_oauth_signup/setup.py b/setup/auth_oauth_signup/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/auth_oauth_signup/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)