-
-
Notifications
You must be signed in to change notification settings - Fork 282
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
[ADD][15.0] base_ical: Module to expose iCalendar over URL #286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
================================ | ||
Readonly publishing of calendars | ||
================================ | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Alpha | ||
.. |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--backend-lightgray.png?logo=github | ||
:target: https://github.com/OCA/server-backend/tree/15.0/base_ical | ||
:alt: OCA/server-backend | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/server-backend-15-0/server-backend-15-0-base_ical | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/server-backend&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows administrators to configure iCalendars based on an arbitrary selection on arbitrary models. | ||
|
||
Users can selectively subscribe to them by enabling them in their profile form. | ||
|
||
This is useful for exposing Odoo data to calendaring application like Nextcloud. | ||
|
||
.. IMPORTANT:: | ||
This is an alpha version, the data model and design can change at any time without warning. | ||
Only for development or testing purpose, do not use in production. | ||
`More details on development status <https://odoo-community.org/page/development-status>`_ | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
To configure this module, you need to: | ||
|
||
#. Go to Settings/Technical/iCalendars | ||
#. Create a iCalendar, fill in the model you want to expose and possibly a domain to restrict records. You can use the ``user`` variable to restrict things relative to the user using the iCalendar | ||
#. A iCalendar is only available to the allowed users. Use the `Allow automatically` to make the iCalendar available to all users | ||
#. See the examples below for a start | ||
|
||
Examples | ||
~~~~~~~~ | ||
|
||
Simple example, for model ``calendar.event``, you'd fill in ``record.allday and record.start_date or record.start`` as `DTSTART` and ``record.allday and record.stop_date or record.stop`` as `DTEND`. | ||
|
||
Advanced example, for model ``calendar.event``, you'd use ``calendar = record._get_ics_file()`` in the code. | ||
|
||
Advanced example, for model ``hr.leave``, you can use the following code and ``[("employee_id.user_id", "=", user.id)]`` in the `domain` to export the own time offs. This is a bit more complex because of the way Odoo handles the begin and end times of leaves, and you'll want the extra day as most clients interpret the end date as non-inclusive.: | ||
|
||
.. code-block:: python | ||
|
||
confirmed = ("validate", "validate1") | ||
if record.request_unit_half or record.request_unit_hours: | ||
event = { | ||
"dtstart": event["dtstart"].date(), | ||
"dtend": event["dtend"].date() + timedelta(days=1), | ||
} | ||
else: | ||
event = { | ||
"dtstart": record.date_from, | ||
"dtend": record.date_to, | ||
} | ||
|
||
event["summary"] = record.name | ||
event["status"] = "CONFIRMED" if record.state in confirmed else "TENTATIVE" | ||
|
||
Advanced example, for model ``mail.activity``, you can use the following code and ``[("user_id", "=", user.id)]`` and `domain` to export all user activities. | ||
|
||
.. code-block:: python | ||
|
||
todo = { | ||
"summary": record.display_name, | ||
"due": record.date_deadline, | ||
"description": html2plaintext(record.note) if record.note else "" | ||
} | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Go to your profile form | ||
#. Click `Enable` on one of the calendars listed in tab `Calendars` | ||
#. Copy the URL to the application you use | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
* support all of https://datatracker.ietf.org/doc/html/rfc5545#section-3.8 | ||
* allow users to define their own calendars | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-backend/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/server-backend/issues/new?body=module:%20base_ical%0Aversion:%2015.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 | ||
~~~~~~~ | ||
|
||
* Hunki Enterprises BV | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Holger Brunn <mail@hunki-enterprises.com> (https://hunki-enterprises.com) | ||
* Florian Kantelberg <florian.kantelberg@initos.com> (https://www.initos.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. | ||
|
||
.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px | ||
:target: https://github.com/hbrunn | ||
:alt: hbrunn | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-hbrunn| | ||
|
||
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/15.0/base_ical>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import controllers |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2023 Hunki Enterprises BV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
{ | ||
"name": "Readonly publishing of calendars", | ||
"summary": "Provide (readonly) .ics URLs to calendar-like models", | ||
"version": "15.0.1.0.0", | ||
"development_status": "Alpha", | ||
"category": "Tools", | ||
"website": "https://github.com/OCA/server-backend", | ||
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)", | ||
"maintainers": ["hbrunn"], | ||
"license": "AGPL-3", | ||
"external_dependencies": { | ||
"python": ["vobject"], | ||
}, | ||
"depends": [ | ||
"web", | ||
], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"views/base_ical.xml", | ||
"views/res_users.xml", | ||
], | ||
"demo": [ | ||
"demo/base_ical.xml", | ||
], | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2023 Hunki Enterprises BV | ||
# Copyright 2024 initOS GmbH | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) | ||
|
||
import logging | ||
|
||
import werkzeug.wrappers | ||
from werkzeug.exceptions import Unauthorized | ||
|
||
from odoo import http | ||
from odoo.http import request | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ICalController(http.Controller): | ||
@http.route( | ||
"/base_ical/<int:calendar_id>", | ||
auth="none", | ||
csrf=False, | ||
methods=["GET"], | ||
type="http", | ||
) | ||
def get_ical(self, calendar_id, access_token=None): | ||
if not access_token: | ||
raise Unauthorized() | ||
|
||
user_id = request.env["res.users.apikeys"]._check_credentials( | ||
scope=f"odoo.plugin.ical.{calendar_id}", | ||
key=access_token, | ||
) | ||
if not user_id: | ||
raise Unauthorized() | ||
|
||
calendar = ( | ||
http.request.env["base.ical"] | ||
.with_user(user_id) | ||
.search([("id", "=", calendar_id)]) | ||
) | ||
if not calendar: | ||
return request.not_found() | ||
|
||
records = calendar._get_items() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My suggestion above means that this call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before is wasn't su too. because as @hbrunn mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it should be as it is - .with_user but no sudo |
||
response = werkzeug.wrappers.Response() | ||
if records: | ||
response.last_modified = max(records.mapped("write_date")) | ||
|
||
response.make_conditional(request.httprequest) | ||
if response.status_code == 304: | ||
return response | ||
|
||
response.mimetype = "text/calendar" | ||
response.data = calendar._get_ical(records) | ||
return response |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2023 Hunki Enterprises BV | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) --> | ||
<data> | ||
<record id="demo_calendar" model="base.ical"> | ||
<field name="name">Demo calendar</field> | ||
<field name="model_id" ref="base.model_res_users" /> | ||
<field name="expression_uid">str(record.id)</field> | ||
<field name="expression_dtstart">record.create_date</field> | ||
<field name="expression_dtend">record.write_date</field> | ||
</record> | ||
</data> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import base_ical, base_ical_url_description, base_ical_url_show, res_users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this land in https://github.com/OCA/calendar instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how we want to sort it. You can publish leaves => holidays. You can publish activities as TODO => social(?). You can publish a calendar => calendar. You can also publish attendance => attendance. server-backend might fit as general place.
You will probably use it in your calendar application but I'm not sure if this is the correct criteria.