mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 23:42:37 -07:00
Add email config to newsletters
This commit is contained in:
parent
edeb6ae4e4
commit
7770431b67
5 changed files with 172 additions and 34 deletions
|
@ -13,6 +13,7 @@
|
|||
<div class="row">
|
||||
<ul class="nav nav-tabs list-unstyled" role="tablist">
|
||||
<li role="presentation" class="active"><a href="#tabs-config" aria-controls="tabs-config" role="tab" data-toggle="tab">Configuration</a></li>
|
||||
<li role="presentation"><a href="#tabs-email_config" aria-controls="tabs-email_config" role="tab" data-toggle="tab">Email Configuration</a></li>
|
||||
<li role="presentation"><a href="#tabs-test_newsletter" aria-controls="tabs-test_newsletter" role="tab" data-toggle="tab">Test Newsletter</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -20,7 +21,7 @@
|
|||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active" id="tabs-config">
|
||||
<div class="row">
|
||||
<div class="col-md-12" style="margin-bottom: 10px; padding-bottom: 0x; border-bottom: 1px solid #444;">
|
||||
<div class="col-md-12">
|
||||
<div class="checkbox" style="margin-bottom: 20px;">
|
||||
<label>
|
||||
<input type="checkbox" data-id="active_value" class="checkboxes" value="1" ${helpers.checked(newsletter['active'])}> Enable the newsletter
|
||||
|
@ -38,7 +39,7 @@
|
|||
<p class="help-block">Set the schedule for the newsletter</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-12" style="padding-top: 10px; border-top: 1px solid #444;">
|
||||
<input type="hidden" id="newsletter_id" name="newsletter_id" value="${newsletter['id']}" />
|
||||
<input type="hidden" id="agent_id" name="agent_id" value="${newsletter['agent_id']}" />
|
||||
% for item in newsletter['config_options']:
|
||||
|
@ -119,6 +120,99 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-email_config">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<label for="email_notifier">Email Notification Agent</label>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" id="email_notifier" name="email_notifier">
|
||||
% for item in newsletter['email_notifiers']:
|
||||
<% selected = 'selected' if item['id'] == newsletter['email_notifier'] else '' %>
|
||||
% if item['friendly_name']:
|
||||
<option value="${item['id']}" ${selected}>${item['agent_label']} (${item['id']} - ${item['friendly_name']})</option>
|
||||
% elif item['id']:
|
||||
<option value="${item['id']}" ${selected}>${item['agent_label']} (${item['id']})</option>
|
||||
% else:
|
||||
<option value="${item['id']}" ${selected}>${item['agent_label']}</option>
|
||||
% endif
|
||||
% endfor
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">Use an exisiting Email notification agent or enter a new configuration below.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="newsletter-email-config" class="col-md-12" style="padding-top: 10px; border-top: 1px solid #444; ${'display: none;' if newsletter['email_notifier'] else ''}">
|
||||
% for item in newsletter['email_config_options']:
|
||||
% if item['input_type'] == 'help':
|
||||
<div class="form-group">
|
||||
<label>${item['label']}</label>
|
||||
<p class="help-block">${item['description'] | n}</p>
|
||||
</div>
|
||||
% elif item['input_type'] == 'text' or item['input_type'] == 'password':
|
||||
<div class="form-group">
|
||||
<label for="${item['name']}">${item['label']}</label>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30" ${'readonly' if item.get('readonly') else ''}>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">${item['description'] | n}</p>
|
||||
</div>
|
||||
% elif item['input_type'] == 'number':
|
||||
<div class="form-group">
|
||||
<label for="${item['name']}">${item['label']}</label>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<input type="${item['input_type']}" class="form-control" id="${item['name']}" name="${item['name']}" value="${item['value']}" size="30">
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">${item['description'] | n}</p>
|
||||
</div>
|
||||
% elif item['input_type'] == 'button':
|
||||
<div class="form-group">
|
||||
<label for="${item['name']}">${item['label']}</label>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<input type="button" class="btn btn-bright" id="${item['name']}" name="${item['name']}" value="${item['value']}">
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">${item['description'] | n}</p>
|
||||
</div>
|
||||
% elif item['input_type'] == 'checkbox' and item['name'] != 'email_html_support':
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" data-id="${item['name']}" class="checkboxes" value="1" ${helpers.checked(item['value'])}> ${item['label']}
|
||||
</label>
|
||||
<p class="help-block">${item['description'] | n}</p>
|
||||
<input type="hidden" id="${item['name']}" name="${item['name']}" value="${item['value']}">
|
||||
</div>
|
||||
% elif item['input_type'] == 'select':
|
||||
<div class="form-group">
|
||||
<label for="${item['name']}">${item['label']}</label>
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<select class="form-control" id="${item['name']}" name="${item['name']}">
|
||||
% for key, value in sorted(item['select_options'].iteritems()):
|
||||
% if key == item['value']:
|
||||
<option value="${key}" selected>${value}</option>
|
||||
% else:
|
||||
<option value="${key}">${value}</option>
|
||||
% endif
|
||||
% endfor
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">${item['description'] | n}</p>
|
||||
</div>
|
||||
% endif
|
||||
% endfor
|
||||
<input type="hidden" id="email_html_support" name="email_html_support" value="1">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="tabs-test_newsletter">
|
||||
<label>Preview Newsletter</label>
|
||||
<p class="help-block">
|
||||
|
@ -168,6 +262,14 @@
|
|||
}
|
||||
}); // apply cron with default options
|
||||
|
||||
$('#email_notifier').change(function () {
|
||||
if ($(this).val() === "0") {
|
||||
$('#newsletter-email-config').show();
|
||||
} else {
|
||||
$('#newsletter-email-config').hide();
|
||||
}
|
||||
});
|
||||
|
||||
function reloadModal() {
|
||||
$.ajax({
|
||||
url: 'get_newsletter_config_modal',
|
||||
|
|
|
@ -624,7 +624,7 @@ def dbcheck():
|
|||
c_db.execute(
|
||||
'CREATE TABLE IF NOT EXISTS newsletters (id INTEGER PRIMARY KEY AUTOINCREMENT, '
|
||||
'agent_id INTEGER, agent_name TEXT, agent_label TEXT, '
|
||||
'friendly_name TEXT, newsletter_config TEXT, '
|
||||
'friendly_name TEXT, newsletter_config TEXT, email_config TEXT, email_notifier INTEGER DEFAULT 0, '
|
||||
'cron TEXT NOT NULL DEFAULT "0 0 * * 0", active INTEGER DEFAULT 0)'
|
||||
)
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import logger
|
|||
import notification_handler
|
||||
import pmsconnect
|
||||
import request
|
||||
from notifiers import get_notifiers, EMAIL
|
||||
|
||||
|
||||
AGENT_IDS = {
|
||||
|
@ -51,14 +52,14 @@ def available_newsletter_agents():
|
|||
return agents
|
||||
|
||||
|
||||
def get_agent_class(agent_id=None, config=None):
|
||||
def get_agent_class(agent_id=None, config=None, email_config=None):
|
||||
if str(agent_id).isdigit():
|
||||
agent_id = int(agent_id)
|
||||
|
||||
if agent_id == 0:
|
||||
return RecentlyAdded(config=config)
|
||||
return RecentlyAdded(config=config, email_config=email_config)
|
||||
else:
|
||||
return Newsletter(config=config)
|
||||
return Newsletter(config=config, email_config=email_config)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -113,14 +114,29 @@ def get_newsletter_config(newsletter_id=None):
|
|||
|
||||
try:
|
||||
config = json.loads(result.pop('newsletter_config') or '{}')
|
||||
newsletter_agent = get_agent_class(agent_id=result['agent_id'], config=config)
|
||||
email_config = json.loads(result.pop('email_config') or '{}')
|
||||
newsletter_agent = get_agent_class(agent_id=result['agent_id'], config=config, email_config=email_config)
|
||||
newsletter_config = newsletter_agent.return_config_options()
|
||||
newsletter_email_config = newsletter_agent.return_email_config_options()
|
||||
except Exception as e:
|
||||
logger.error(u"Tautulli Newsletters :: Failed to get newsletter config options: %s." % e)
|
||||
return
|
||||
|
||||
notifiers = []
|
||||
for n in get_notifiers():
|
||||
if n['agent_name'] == 'email':
|
||||
notifiers.append({
|
||||
'id': n['id'],
|
||||
'agent_label': n['agent_label'],
|
||||
'friendly_name': n['friendly_name']
|
||||
})
|
||||
sorted(notifiers, key=lambda k: (k['agent_label'], k['friendly_name'], k['id']))
|
||||
email_notifiers = [{'id': 0, 'agent_label': 'New Email Configuration', 'friendly_name': ''}] + notifiers
|
||||
|
||||
result['config'] = config
|
||||
result['config_options'] = newsletter_config
|
||||
result['email_config_options'] = newsletter_email_config
|
||||
result['email_notifiers'] = email_notifiers
|
||||
|
||||
return result
|
||||
|
||||
|
@ -140,12 +156,15 @@ def add_newsletter_config(agent_id=None, **kwargs):
|
|||
% agent_id)
|
||||
return False
|
||||
|
||||
agent_class = get_agent_class(agent_id=agent['id'])
|
||||
|
||||
keys = {'id': None}
|
||||
values = {'agent_id': agent['id'],
|
||||
'agent_name': agent['name'],
|
||||
'agent_label': agent['label'],
|
||||
'friendly_name': '',
|
||||
'newsletter_config': json.dumps(get_agent_class(agent_id=agent['id']).config)
|
||||
'newsletter_config': json.dumps(agent_class.config),
|
||||
'email_config': json.dumps(agent_class.email_config)
|
||||
}
|
||||
|
||||
db = database.MonitorDatabase()
|
||||
|
@ -176,17 +195,25 @@ def set_newsletter_config(newsletter_id=None, agent_id=None, **kwargs):
|
|||
return False
|
||||
|
||||
config_prefix = agent['name'] + '_'
|
||||
email_config_prefix = 'email_'
|
||||
|
||||
newsletter_config = {k[len(config_prefix):]: kwargs.pop(k)
|
||||
for k in kwargs.keys() if k.startswith(config_prefix)}
|
||||
newsletter_config = get_agent_class(agent['id']).set_config(config=newsletter_config)
|
||||
|
||||
email_notifier = kwargs.pop('email_notifier', 0)
|
||||
email_config = {k[len(config_prefix):]: kwargs.pop(k)
|
||||
for k in kwargs.keys() if k.startswith(email_config_prefix)}
|
||||
|
||||
agent_class = get_agent_class(agent_id=agent['id'], config=newsletter_config, email_config=email_config)
|
||||
|
||||
keys = {'id': newsletter_id}
|
||||
values = {'agent_id': agent['id'],
|
||||
'agent_name': agent['name'],
|
||||
'agent_label': agent['label'],
|
||||
'friendly_name': kwargs.get('friendly_name', ''),
|
||||
'newsletter_config': json.dumps(newsletter_config),
|
||||
'newsletter_config': json.dumps(agent_class.config),
|
||||
'email_config': json.dumps(agent_class.email_config),
|
||||
'email_notifier': email_notifier,
|
||||
'cron': kwargs.get('cron'),
|
||||
'active': kwargs.get('active')
|
||||
}
|
||||
|
@ -206,7 +233,8 @@ def send_newsletter(newsletter_id=None, newsletter_log_id=None, **kwargs):
|
|||
newsletter_config = get_newsletter_config(newsletter_id=newsletter_id)
|
||||
if newsletter_config:
|
||||
agent = get_agent_class(agent_id=newsletter_config['agent_id'],
|
||||
config=newsletter_config['config'])
|
||||
config=newsletter_config['config'],
|
||||
email_config=newsletter_config['email_config'])
|
||||
return agent.send(newsletter_log_id=newsletter_log_id, **kwargs)
|
||||
else:
|
||||
logger.debug(u"Tautulli Newsletters :: Notification requested but no newsletter_id received.")
|
||||
|
@ -228,21 +256,21 @@ def serve_template(templatename, **kwargs):
|
|||
class Newsletter(object):
|
||||
NAME = ''
|
||||
_DEFAULT_CONFIG = {}
|
||||
_DEFAULT_EMAIL_CONFIG = EMAIL._DEFAULT_CONFIG
|
||||
|
||||
def __init__(self, config=None):
|
||||
self.config = {}
|
||||
self.set_config(config)
|
||||
def __init__(self, config=None, email_config=None):
|
||||
self.config = self.set_config(config=config, default=self._DEFAULT_CONFIG)
|
||||
self.email_config = self.set_config(config=email_config, default=self._DEFAULT_EMAIL_CONFIG)
|
||||
|
||||
def set_config(self, config=None):
|
||||
self.config = self._validate_config(config)
|
||||
return self.config
|
||||
def set_config(self, config=None, default=None):
|
||||
return self._validate_config(config=config, default=default)
|
||||
|
||||
def _validate_config(self, config=None):
|
||||
def _validate_config(self, config=None, default=None):
|
||||
if config is None:
|
||||
return self._DEFAULT_CONFIG
|
||||
return default
|
||||
|
||||
new_config = {}
|
||||
for k, v in self._DEFAULT_CONFIG.iteritems():
|
||||
for k, v in default.iteritems():
|
||||
if isinstance(v, int):
|
||||
new_config[k] = helpers.cast_to_int(config.get(k, v))
|
||||
else:
|
||||
|
@ -282,6 +310,9 @@ class Newsletter(object):
|
|||
config_options = []
|
||||
return config_options
|
||||
|
||||
def return_email_config_options(self):
|
||||
return EMAIL(self.email_config).return_config_options()
|
||||
|
||||
|
||||
class RecentlyAdded(Newsletter):
|
||||
"""
|
||||
|
@ -295,8 +326,8 @@ class RecentlyAdded(Newsletter):
|
|||
}
|
||||
_TEMPLATE = 'recently_added.html'
|
||||
|
||||
def __init__(self, config=None):
|
||||
super(RecentlyAdded, self).__init__(config)
|
||||
def __init__(self, config=None, email_config=None):
|
||||
super(RecentlyAdded, self).__init__(config=config, email_config=email_config)
|
||||
|
||||
date_format = helpers.momentjs_to_arrow(plexpy.CONFIG.DATE_FORMAT)
|
||||
|
||||
|
|
|
@ -502,6 +502,8 @@ def add_notifier_config(agent_id=None, **kwargs):
|
|||
% agent_id)
|
||||
return False
|
||||
|
||||
agent_class = get_agent_class(agent_id=agent['id'])
|
||||
|
||||
keys = {'id': None}
|
||||
values = {'agent_id': agent['id'],
|
||||
'agent_name': agent['name'],
|
||||
|
@ -511,6 +513,7 @@ def add_notifier_config(agent_id=None, **kwargs):
|
|||
'custom_conditions': json.dumps(DEFAULT_CUSTOM_CONDITIONS),
|
||||
'custom_conditions_logic': ''
|
||||
}
|
||||
|
||||
if agent['name'] == 'scripts':
|
||||
for a in available_notification_actions():
|
||||
values[a['name'] + '_subject'] = ''
|
||||
|
@ -559,7 +562,8 @@ def set_notifier_config(notifier_id=None, agent_id=None, **kwargs):
|
|||
for k in kwargs.keys() if k.startswith(notify_actions) and k.endswith('_body')}
|
||||
notifier_config = {k[len(config_prefix):]: kwargs.pop(k)
|
||||
for k in kwargs.keys() if k.startswith(config_prefix)}
|
||||
notifier_config = get_agent_class(agent['id']).set_config(config=notifier_config)
|
||||
|
||||
agent_class = get_agent_class(agent_id=agent['id'], config=notifier_config)
|
||||
|
||||
keys = {'id': notifier_id}
|
||||
values = {'agent_id': agent['id'],
|
||||
|
@ -750,19 +754,17 @@ class Notifier(object):
|
|||
_DEFAULT_CONFIG = {}
|
||||
|
||||
def __init__(self, config=None):
|
||||
self.config = {}
|
||||
self.set_config(config)
|
||||
self.config = self.set_config(config=config, default=self._DEFAULT_CONFIG)
|
||||
|
||||
def set_config(self, config=None):
|
||||
self.config = self._validate_config(config)
|
||||
return self.config
|
||||
def set_config(self, config=None, default=None):
|
||||
return self._validate_config(config=config, default=default)
|
||||
|
||||
def _validate_config(self, config=None):
|
||||
def _validate_config(self, config=None, default=None):
|
||||
if config is None:
|
||||
return self._DEFAULT_CONFIG
|
||||
return default
|
||||
|
||||
new_config = {}
|
||||
for k, v in self._DEFAULT_CONFIG.iteritems():
|
||||
for k, v in default.iteritems():
|
||||
if isinstance(v, int):
|
||||
new_config[k] = helpers.cast_to_int(config.get(k, v))
|
||||
else:
|
||||
|
@ -2332,7 +2334,7 @@ class OSX(Notifier):
|
|||
}
|
||||
|
||||
def __init__(self, config=None):
|
||||
self.set_config(config)
|
||||
super(OSX, self).__init__(config=config)
|
||||
|
||||
try:
|
||||
self.objc = __import__("objc")
|
||||
|
@ -2925,7 +2927,8 @@ class SCRIPTS(Notifier):
|
|||
}
|
||||
|
||||
def __init__(self, config=None):
|
||||
self.set_config(config)
|
||||
super(SCRIPTS, self).__init__(config=config)
|
||||
|
||||
self.script_exts = {'.bat': '',
|
||||
'.cmd': '',
|
||||
'.exe': '',
|
||||
|
|
|
@ -5403,7 +5403,9 @@ class WebInterface(object):
|
|||
"incl_shows": 1,
|
||||
"incl_artists": 1,
|
||||
},
|
||||
"config_options": [{...}, ...]
|
||||
"config_options": [{...}, ...],
|
||||
"email_config_options": [{...}, ...],
|
||||
"email_notifier": 0
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue