Skip to content

Commit

Permalink
[ADD] website_event_private: new module
Browse files Browse the repository at this point in the history
  • Loading branch information
benj-filament authored and remi-filament committed Jul 9, 2024
1 parent 7b13259 commit 626f47d
Show file tree
Hide file tree
Showing 21 changed files with 825 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_event_private/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
101 changes: 101 additions & 0 deletions website_event_private/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
=====================
Website Event Private
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e2fa0df647bdf86e9ad2ca5b9877819b436963e805bc2b4de1237d0e104d109d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fevent-lightgray.png?logo=github
:target: https://github.com/OCA/event/tree/16.0/website_event_private
:alt: OCA/event
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/event-16-0/event-16-0-website_event_private
: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/event&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows you to configure the privacy of website events :

* *Public*: anyone can view the event and register
* *Private displayed*: the event appears in the event list (but not clickable) and one needs access token to see content / register
* *Private hidden*: the event does not appear in the list of events and one needs access token to see content / register

**Table of contents**

.. contents::
:local:

Configuration
=============


To configure this module, you need to:

#. Go to an event and set the privacy option
#. If you select private displayed or hidden, access token link will appear just after the privacy field

Usage
=====

On private event record, you need to share the access link which is generated
and accessible on backend event form to give access to the event.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/event/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 <https://github.com/OCA/event/issues/new?body=module:%20website_event_private%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Le Filament

Contributors
~~~~~~~~~~~~

* Juliana <JulianaPoudou>
* Benjamin <benj-filament>

Other credits
~~~~~~~~~~~~~

* Le Filament <https://www.le-filament.com>

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/event <https://github.com/OCA/event/tree/16.0/website_event_private>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions website_event_private/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
23 changes: 23 additions & 0 deletions website_event_private/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "Website Event Private",
"summary": "Website Event Private",
"version": "16.0.1.0.0",
"author": "Le Filament, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/event",
"application": False,
"category": "Marketing",
"depends": ["website_event"],
"data": [
"templates/event_templates_list.xml",
"views/event_views.xml",
"views/event_type_views.xml",
],
"assets": {
"web.assets_frontend": [
"website_event_private/static/src/scss/website_event_private.scss",
],
},
"installable": True,
"auto_install": False,
}
1 change: 1 addition & 0 deletions website_event_private/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
62 changes: 62 additions & 0 deletions website_event_private/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2023- Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import http
from odoo.http import request

from odoo.addons.website_event.controllers.main import WebsiteEventController


class WebsiteEvent(WebsiteEventController):
# ------------------------------------------------------
# Inherit parent routes
# ------------------------------------------------------
@http.route()
def event_page(self, event, page, **post):
if not self._check_privacy(event, **post):
return request.redirect("/event")

Check warning on line 17 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L17

Added line #L17 was not covered by tests

return super(WebsiteEvent, self).event_page(event, page, **post)

Check warning on line 19 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L19

Added line #L19 was not covered by tests

@http.route()
def event(self, event, **post):
if not self._check_privacy(event, **post):
return request.redirect("/event")

Check warning on line 24 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L24

Added line #L24 was not covered by tests

return super(WebsiteEvent, self).event(event, **post)

Check warning on line 26 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L26

Added line #L26 was not covered by tests

@http.route()
def event_register(self, event, **post):
if not self._check_privacy(event, **post):
return request.redirect("/event")

Check warning on line 31 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L31

Added line #L31 was not covered by tests

return super(WebsiteEvent, self).event_register(event, **post)

Check warning on line 33 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L33

Added line #L33 was not covered by tests

# ------------------------------------------------------
# Business method
# ------------------------------------------------------
def _check_privacy(self, event, **post):
if event.event_privacy != "public" and not request.env.user.has_group(
"website.group_website_restricted_editor"
):
cookie = request.httprequest.cookies.get("odoo-event-%d" % event.id)

Check warning on line 42 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L42

Added line #L42 was not covered by tests
if (
post
and post.get("access_token")
and post.get("access_token") == event.access_token
):
access_token = post.get("access_token")
request.future_response.set_cookie(

Check warning on line 49 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L48-L49

Added lines #L48 - L49 were not covered by tests
key="odoo-event-%d" % event.id,
value=access_token,
max_age=10 * 86400,
secure=True,
httponly=True,
samesite="Strict",
)
return True

Check warning on line 57 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L57

Added line #L57 was not covered by tests
elif cookie and cookie == event.access_token:
return True

Check warning on line 59 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L59

Added line #L59 was not covered by tests
else:
return False
return True

Check warning on line 62 in website_event_private/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/controllers/main.py#L61-L62

Added lines #L61 - L62 were not covered by tests
2 changes: 2 additions & 0 deletions website_event_private/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import event_type
from . import event_event
69 changes: 69 additions & 0 deletions website_event_private/models/event_event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2023- Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import uuid

from odoo import api, fields, models


class Event(models.Model):
_inherit = "event.event"

access_token = fields.Char(
string="Security Token", compute="_compute_access_token", store=True, copy=False
)
event_share_link = fields.Char(
string="Event link",
compute="_compute_event_share_link",
)
event_privacy = fields.Selection(
[
("public", "Public"),
("private_displayed", "Private displayed"),
("private_hidden", "Private hidden"),
],
string="Event privacy",
default="public",
required=True,
readonly=False,
store=True,
compute="_compute_event_privacy",
)

# ------------------------------------------------------
# Computed fields / Search Fields
# ------------------------------------------------------
@api.depends("event_type_id")
def _compute_event_privacy(self):
for event in self:
event.event_privacy = event.event_type_id.event_privacy

@api.depends("event_privacy")
def _compute_access_token(self):
for event in self:
if event.event_privacy != "public" and not event.access_token:
event.access_token = str(uuid.uuid4())

Check warning on line 45 in website_event_private/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/models/event_event.py#L45

Added line #L45 was not covered by tests

def _compute_event_share_link(self):
for event in self:
if event.id and event.access_token and event.event_privacy != "public":
event.event_share_link = (

Check warning on line 50 in website_event_private/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/models/event_event.py#L50

Added line #L50 was not covered by tests
event.get_base_url()
+ "/event/"
+ str(event.id)
+ "?access_token="
+ event.access_token
)
else:
event.event_share_link = ""

Check warning on line 58 in website_event_private/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/models/event_event.py#L58

Added line #L58 was not covered by tests

# ------------------------------------------------------
# Inherit parent
# ------------------------------------------------------
@api.model
def _search_get_detail(self, website, order, options):
result = super(Event, self)._search_get_detail(website, order, options)

Check warning on line 65 in website_event_private/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/models/event_event.py#L65

Added line #L65 was not covered by tests
if not self.env.user.has_group("website.group_website_restricted_editor"):
result["base_domain"].append([("event_privacy", "!=", "private_hidden")])

Check warning on line 67 in website_event_private/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/models/event_event.py#L67

Added line #L67 was not covered by tests

return result

Check warning on line 69 in website_event_private/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

website_event_private/models/event_event.py#L69

Added line #L69 was not covered by tests
19 changes: 19 additions & 0 deletions website_event_private/models/event_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023- Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class EventType(models.Model):
_inherit = "event.type"

event_privacy = fields.Selection(
[
("public", "Public"),
("private_displayed", "Private displayed"),
("private_hidden", "Private hidden"),
],
string="Event privacy",
default="public",
required=True,
)
5 changes: 5 additions & 0 deletions website_event_private/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

To configure this module, you need to:

#. Go to an event and set the privacy option
#. If you select private displayed or hidden, access token link will appear just after the privacy field
2 changes: 2 additions & 0 deletions website_event_private/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Juliana <JulianaPoudou>
* Benjamin <benj-filament>
1 change: 1 addition & 0 deletions website_event_private/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Le Filament <https://www.le-filament.com>
5 changes: 5 additions & 0 deletions website_event_private/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module allows you to configure the privacy of website events :

* *Public*: anyone can view the event and register
* *Private displayed*: the event appears in the event list (but not clickable) and one needs access token to see content / register
* *Private hidden*: the event does not appear in the list of events and one needs access token to see content / register
2 changes: 2 additions & 0 deletions website_event_private/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
On private event record, you need to share the access link which is generated
and accessible on backend event form to give access to the event.
Binary file added website_event_private/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 626f47d

Please sign in to comment.