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

[14.0] database_expiration #274

Merged
merged 17 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions database_block/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. image:: https://itpp.dev/images/infinity-readme.png
:alt: Tested and maintained by IT Projects Labs
:target: https://itpp.dev

.. image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://opensource.org/licenses/MIT
:alt: License: MIT

==================
Block backend UI
==================

This technical module allows blocking backend access and display the message

In order to do that, dependent module need to override ``ir.http`` 's session_info method and return
dictionary with following keys:

* ``database_block_message`` - the displayed message itself. Can be HTML
* ``database_block_is_warning`` - if true, backend is not blocked, but displayed message is shown as warning (``web_responsive`` must be installed in order for warning to be displayed)

Questions?
==========

To get an assistance on this module contact us by email :arrow_right: [email protected]

Contributors
============
* `Eugene Molotov <https://it-projects.info/team/em230418>`__:


Further information
===================

Odoo Apps Store: https://apps.odoo.com/apps/modules/14.0/database_block/


Notifications on updates: `via Atom <https://github.com/itpp-labs/access-addons/commits/14.0/database_block.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/itpp-labs/access-addons/commits/14.0/database_block.atom>`_

Tested on `Odoo 14.0 <https://github.com/odoo/odoo/commit/829ae7b7e2941b6bb7af73a6d3d78b4ef1abf453>`_
1 change: 1 addition & 0 deletions database_block/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
26 changes: 26 additions & 0 deletions database_block/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
# License MIT (https://opensource.org/licenses/MIT).

{
"name": """Block backend UI""",
"summary": """This technical module allows blocking backend access and display the message""",
"category": "Extra Tools",
"images": [],
"version": "14.0.1.0.0",
"application": False,
"author": "IT-Projects LLC, Eugene Molotov",
"support": "[email protected]",
"website": "https://twitter.com/OdooFree",
"license": "Other OSI approved licence", # MIT
"depends": ["web"],
"external_dependencies": {"python": [], "bin": []},
"data": ["views/assets.xml"],
"demo": [],
"qweb": ["static/src/xml/apps.xml"],
"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"uninstall_hook": None,
"auto_install": False,
"installable": True,
}
4 changes: 4 additions & 0 deletions database_block/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
`1.0.0`
-------

- **Init version**
8 changes: 8 additions & 0 deletions database_block/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
==================
Block backend UI
==================

Installation
============

* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way
3 changes: 3 additions & 0 deletions database_block/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License MIT (https://opensource.org/licenses/MIT).

from . import ir_http
23 changes: 23 additions & 0 deletions database_block/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
# License MIT (https://opensource.org/licenses/MIT).

from odoo import SUPERUSER_ID, models


class IrHttp(models.AbstractModel):

_inherit = "ir.http"

def session_info(self):
res = super(IrHttp, self).session_info()

res["database_block_show_message_in_apps_menu"] = bool(
self.env["ir.module.module"]
.with_user(SUPERUSER_ID)
.search(
[("name", "=", "web_responsive"), ("state", "=", "installed")],
limit=1,
)
)

return res
Binary file added database_block/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.
4 changes: 4 additions & 0 deletions database_block/static/src/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.dropdown-menu > .database_block_message {
width: 100%;
text-align: center;
}
32 changes: 32 additions & 0 deletions database_block/static/src/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
License MIT (https://opensource.org/licenses/MIT). */
odoo.define("database_block.main", function (require) {
"use strict";

var AppsMenu = require("web.AppsMenu");

AppsMenu.include({
start: function () {
this._super.apply(this, arguments);

if (odoo.session_info.database_block_message) {
$(".database_block_message").html(
odoo.session_info.database_block_message
);

if (!odoo.session_info.database_block_is_warning) {
$(".o_action_manager").block({
message: $(".block_ui.database_block_message").html(
odoo.session_info.database_block_message
),
});
$("header").css("z-index", $.blockUI.defaults.baseZ + 20);
}

if (odoo.session_info.database_block_show_message_in_apps_menu) {
$(".dropdown-menu > .database_block_message").show();
}
}
},
});
});
21 changes: 21 additions & 0 deletions database_block/static/src/xml/apps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
License MIT (https://opensource.org/licenses/MIT). -->
<template>
<t t-extend="AppsMenu">
<t t-jquery=".dropdown-menu" t-operation="prepend">
<div
class="alert alert-info database_block_message"
style="display: none"
/>
<div style="display: none">
<div
class="block_ui database_block_message alert alert-danger"
onclick="$('a.full').trigger('click');"
>
Your database is blocked
</div>
</div>
</t>
</t>
</template>
17 changes: 17 additions & 0 deletions database_block/views/assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
License MIT (https://opensource.org/licenses/MIT). -->
<odoo>
<template id="saas_expiration_build" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/database_block/static/src/js/main.js"
/>
<link
rel="stylesheet"
type="text/css"
href="/database_block/static/src/css/main.css"
/>
</xpath>
</template>
</odoo>
43 changes: 43 additions & 0 deletions database_expiration/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.. image:: https://itpp.dev/images/infinity-readme.png
:alt: Tested and maintained by IT Projects Labs
:target: https://itpp.dev

.. image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://opensource.org/licenses/MIT
:alt: License: MIT

=====================
Database expiration
=====================

With this module you can make database to expire.

After reaching expiration date "Your database is expired" will be shown.
Expiration date is defined in "System Parameters" as `database_expiration_date`.

Also if ``web_responsive`` is installed, 7 days before expiration date
module will start to show warning in main menu.
To configure how many days to show warning in advance, you can set ``database_expiration_warning_delay`` in "System Parameters"

You can also add hyperlink below warning/expiration message. To define url, set ``database_expiration_details_link`` in "System Parameters".
By default hyperlink's label is "Details". To define the other one, set ``database_expiraation_details_link_label`` in "System Paramters".

Questions?
==========

To get an assistance on this module contact us by email :arrow_right: [email protected]

Contributors
============
* `Eugene Molotov <https://it-projects.info/team/em230418>`__:


Further information
===================

Odoo Apps Store: https://apps.odoo.com/apps/modules/14.0/database_expiration/


Notifications on updates: `via Atom <https://github.com/itpp-labs/access-addons/commits/14.0/database_expiration.atom>`_, `by Email <https://blogtrottr.com/?subscribe=https://github.com/itpp-labs/access-addons/commits/14.0/database_expiration.atom>`_

Tested on `Odoo 14.0 <https://github.com/odoo/odoo/commit/829ae7b7e2941b6bb7af73a6d3d78b4ef1abf453>`_
1 change: 1 addition & 0 deletions database_expiration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
27 changes: 27 additions & 0 deletions database_expiration/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
# Copyright 2021 Denis Mudarisov <https://github.com/trojikman>
# License MIT (https://opensource.org/licenses/MIT).

{
"name": """Database expiration""",
"summary": """With this module you can make database to expire""",
"category": "Hidden",
"images": [],
"version": "14.0.1.1.1",
"application": False,
"author": "IT-Projects LLC, Eugene Molotov",
"support": "[email protected]",
"website": "https://twitter.com/OdooFree",
"license": "Other OSI approved licence", # MIT
"depends": ["database_block"],
"external_dependencies": {"python": [], "bin": []},
"data": [],
"demo": [],
"qweb": [],
"post_load": None,
"pre_init_hook": None,
"post_init_hook": None,
"uninstall_hook": None,
"auto_install": False,
"installable": True,
}
15 changes: 15 additions & 0 deletions database_expiration/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
`1.1.1`
-------

- **Fix:** in cases when the database expires today or tomorrow no reminder was shown

`1.1.0`
-------

- **New**: ``database_expiration_warning_delay`` option
- **New**: Ability to add hyperlink in warning/expiration message

`1.0.0`
-------

- **Init version**
18 changes: 18 additions & 0 deletions database_expiration/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=====================
Database expiration
=====================

Installation
============
* `Install <https://odoo-development.readthedocs.io/en/latest/odoo/usage/install-module.html>`__ this module in a usual way

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

* `Log in as admin
* `Activate Developer Mode <https://odoo-development.readthedocs.io/en/latest/odoo/usage/debug-mode.html>`__
* Open menu ``[[ Settings ]] >> Technical >> System Parameters``
* Edit existing record by key `database_expiration_date` or create new one
* Set date with format YYYY-MM-DD HH:MM:SS, click "Save" and reload web page
* If you set past date, "Your database is expired" will appear and will disable navigating
* If you set future date in range of 7 days and you have installed `web_responsive` module installed, you will see warning message in main menu page
3 changes: 3 additions & 0 deletions database_expiration/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License MIT (https://opensource.org/licenses/MIT).

from . import ir_http
88 changes: 88 additions & 0 deletions database_expiration/models/ir_http.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2020 Eugene Molotov <https://it-projects.info/team/em230418>
# Copyright 2021 Denis Mudarisov <https://github.com/trojikman>
# License MIT (https://opensource.org/licenses/MIT).

import logging
from datetime import datetime

from mako.template import Template

from odoo import models
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT

_logger = logging.getLogger(__name__)
DATABASE_BLOCK_MESSAGE_HTML_TEMPLATE = Template(
"<p>${database_block_message}</p><a href='${database_expiration_link}'>${database_expiration_link_label}</a>"
)


class IrHttp(models.AbstractModel):

_inherit = "ir.http"

def session_info(self):
res = super(IrHttp, self).session_info()

now = datetime.now()
Config = self.env["ir.config_parameter"].sudo()
database_expiration_date = Config.get_param("database_expiration_date", None)

# Note:
# DO NOT USE database.expiration_date (with dot)
# it will be overwritten here: https://github.com/odoo/odoo/blob/f9a559f5455a4b964de9a99ff05756302071e959/addons/mail/models/update.py#L114

if database_expiration_date:
database_expiration_date = datetime.strptime(
database_expiration_date, DEFAULT_SERVER_DATETIME_FORMAT
)
delta = database_expiration_date - now

try:
database_expiration_warning_delay = int(
Config.get_param("database_expiration_warning_delay", 7)
)
if not database_expiration_warning_delay > 1:
raise ValueError("Value must be greater than 1")
except ValueError as e:
_logger.warning(
"Could not get expiration warning delay: %s. Using default: 7 days"
% str(e)
)
database_expiration_warning_delay = 7

if now > database_expiration_date:
res["database_block_message"] = "Your database is expired"
elif delta.days > database_expiration_warning_delay:
pass
elif delta.days > 1:
res[
"database_block_message"
] = "Your database will expire in {} days".format(
delta.days,
)
res["database_block_is_warning"] = True
elif delta.days == 1:
res["database_block_message"] = "Your database will expire tomorrow"
res["database_block_is_warning"] = True
elif delta.days == 0:
res["database_block_message"] = "Your database will expire today"
res["database_block_is_warning"] = True

if res.get("database_block_message"):
database_expiration_link = Config.get_param(
"database_expiration_details_link", None
)

if database_expiration_link:
database_expiration_link_label = Config.get_param(
"database_expiration_details_link_label", "Details"
)
res[
"database_block_message"
] = DATABASE_BLOCK_MESSAGE_HTML_TEMPLATE.render(
database_block_message=res["database_block_message"],
database_expiration_link=database_expiration_link,
database_expiration_link_label=database_expiration_link_label,
)

return res
Binary file added database_expiration/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