mirror of
https://github.com/jellyfin/jellyfin-plugin-webhook.git
synced 2024-11-23 14:09:55 +00:00
Add user filter per webhook
This commit is contained in:
parent
8144f30734
commit
873b23d6ff
@ -53,6 +53,13 @@
|
|||||||
<span data-name="notificationTypeName"></span>
|
<span data-name="notificationTypeName"></span>
|
||||||
</label>
|
</label>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template id="template-user-filter">
|
||||||
|
<label class="checkboxContainer">
|
||||||
|
<input is="emby-checkbox" type="checkbox" data-name="userFilterValue"/>
|
||||||
|
<span data-name="userFilterName"></span>
|
||||||
|
</label>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template id="template-base">
|
<template id="template-base">
|
||||||
<div class="inputContainer">
|
<div class="inputContainer">
|
||||||
@ -68,6 +75,11 @@
|
|||||||
<div data-name="notificationTypeContainer">
|
<div data-name="notificationTypeContainer">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label>User Filter:</label>
|
||||||
|
<div data-name="userFilterContainer">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label>Item Type:</label>
|
<label>Item Type:</label>
|
||||||
<label class="checkboxContainer">
|
<label class="checkboxContainer">
|
||||||
|
@ -78,13 +78,49 @@
|
|||||||
},
|
},
|
||||||
get: function (container) {
|
get: function (container) {
|
||||||
const notificationTypes = [];
|
const notificationTypes = [];
|
||||||
const checkboxes = container.querySelectorAll('[data-name=notificationTypeValue]:checked')
|
const checkboxes = container.querySelectorAll('[data-name=notificationTypeValue]:checked');
|
||||||
for (const checkbox of checkboxes) {
|
for (const checkbox of checkboxes) {
|
||||||
notificationTypes.push(checkbox.dataset.value);
|
notificationTypes.push(checkbox.dataset.value);
|
||||||
}
|
}
|
||||||
return notificationTypes;
|
return notificationTypes;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
userFilter: {
|
||||||
|
template: document.querySelector("#template-user-filter"),
|
||||||
|
users: [],
|
||||||
|
populate: async function () {
|
||||||
|
const users = await window.ApiClient.getUsers();
|
||||||
|
|
||||||
|
Webhook.userFilter.users = [];
|
||||||
|
for (const user of users) {
|
||||||
|
Webhook.userFilter.users.push({
|
||||||
|
id: user.Id,
|
||||||
|
name: user.Name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
create: function (container, selected = []) {
|
||||||
|
for (const user of Webhook.userFilter.users) {
|
||||||
|
const template = Webhook.userFilter.template.cloneNode(true).content;
|
||||||
|
const name = template.querySelector("[data-name=userFilterName]");
|
||||||
|
const value = template.querySelector("[data-name=userFilterValue]");
|
||||||
|
|
||||||
|
name.innerText = user.name;
|
||||||
|
value.dataset.value = user.id;
|
||||||
|
value.checked = selected.includes(user.id);
|
||||||
|
|
||||||
|
container.appendChild(template);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get: function (container) {
|
||||||
|
const userFilter = [];
|
||||||
|
const checkboxes = container.querySelectorAll('[data-name=userFilterValue]:checked');
|
||||||
|
for (const checkbox of checkboxes) {
|
||||||
|
userFilter.push(checkbox.dataset.value);
|
||||||
|
}
|
||||||
|
return userFilter;
|
||||||
|
}
|
||||||
|
},
|
||||||
baseConfig: {
|
baseConfig: {
|
||||||
template: document.querySelector("#template-base"),
|
template: document.querySelector("#template-base"),
|
||||||
addConfig: function (template, destinationType, destinationName) {
|
addConfig: function (template, destinationType, destinationName) {
|
||||||
@ -130,6 +166,9 @@
|
|||||||
|
|
||||||
const notificationTypeContainer = element.querySelector("[data-name=notificationTypeContainer]");
|
const notificationTypeContainer = element.querySelector("[data-name=notificationTypeContainer]");
|
||||||
Webhook.notificationType.create(notificationTypeContainer, config.NotificationTypes);
|
Webhook.notificationType.create(notificationTypeContainer, config.NotificationTypes);
|
||||||
|
|
||||||
|
const userFilterContainer = element.querySelector("[data-name=userFilterContainer]");
|
||||||
|
Webhook.userFilter.create(userFilterContainer, config.UserFilter);
|
||||||
},
|
},
|
||||||
getConfig: function (element) {
|
getConfig: function (element) {
|
||||||
const config = {};
|
const config = {};
|
||||||
@ -147,7 +186,9 @@
|
|||||||
|
|
||||||
config.NotificationTypes = [];
|
config.NotificationTypes = [];
|
||||||
config.NotificationTypes = Webhook.notificationType.get(element);
|
config.NotificationTypes = Webhook.notificationType.get(element);
|
||||||
console.log(config.NotificationTypes);
|
|
||||||
|
config.UserFilter = [];
|
||||||
|
config.UserFilter = Webhook.userFilter.get(element);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -447,7 +488,7 @@
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
init: function () {
|
init: async function () {
|
||||||
// Add click handlers
|
// Add click handlers
|
||||||
Webhook.discord.btnAdd.addEventListener("click", Webhook.discord.addConfig);
|
Webhook.discord.btnAdd.addEventListener("click", Webhook.discord.addConfig);
|
||||||
Webhook.generic.btnAdd.addEventListener("click", Webhook.generic.addConfig);
|
Webhook.generic.btnAdd.addEventListener("click", Webhook.generic.addConfig);
|
||||||
@ -458,6 +499,7 @@
|
|||||||
Webhook.smtp.btnAdd.addEventListener("click", Webhook.smtp.addConfig);
|
Webhook.smtp.btnAdd.addEventListener("click", Webhook.smtp.addConfig);
|
||||||
document.querySelector("#saveConfig").addEventListener("click", Webhook.saveConfig);
|
document.querySelector("#saveConfig").addEventListener("click", Webhook.saveConfig);
|
||||||
|
|
||||||
|
await Webhook.userFilter.populate();
|
||||||
Webhook.loadConfig();
|
Webhook.loadConfig();
|
||||||
},
|
},
|
||||||
removeConfig: function (e) {
|
removeConfig: function (e) {
|
||||||
@ -569,7 +611,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
view.addEventListener("viewshow", function (e) {
|
view.addEventListener("viewshow", async function () {
|
||||||
Webhook.init();
|
await Webhook.init();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,11 @@ namespace Jellyfin.Plugin.Webhook.Destinations
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Template { get; set; }
|
public string? Template { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the webhook user filter.
|
||||||
|
/// </summary>
|
||||||
|
public Guid[] UserFilter { get; set; } = Array.Empty<Guid>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the compiled handlebars template.
|
/// Gets the compiled handlebars template.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -37,6 +37,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Discord
|
|||||||
throw new ArgumentException(nameof(options.WebhookUri));
|
throw new ArgumentException(nameof(options.WebhookUri));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add discord specific properties.
|
// Add discord specific properties.
|
||||||
data["MentionType"] = GetMentionType(options.MentionType);
|
data["MentionType"] = GetMentionType(options.MentionType);
|
||||||
if (!string.IsNullOrEmpty(options.EmbedColor))
|
if (!string.IsNullOrEmpty(options.EmbedColor))
|
||||||
|
@ -34,6 +34,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Generic
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var field in options.Fields)
|
foreach (var field in options.Fields)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(field.Key) || string.IsNullOrEmpty(field.Value))
|
if (string.IsNullOrEmpty(field.Key) || string.IsNullOrEmpty(field.Value))
|
||||||
|
@ -36,6 +36,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Gotify
|
|||||||
throw new ArgumentException(nameof(options.WebhookUri));
|
throw new ArgumentException(nameof(options.WebhookUri));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add gotify specific properties.
|
// Add gotify specific properties.
|
||||||
data["Priority"] = options.Priority;
|
data["Priority"] = options.Priority;
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -32,6 +33,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Pushbullet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data["PushbulletToken"] = options.Token;
|
data["PushbulletToken"] = options.Token;
|
||||||
data["PushbulletDeviceId"] = options.DeviceId;
|
data["PushbulletDeviceId"] = options.DeviceId;
|
||||||
data["PushbulletChannel"] = options.Channel;
|
data["PushbulletChannel"] = options.Channel;
|
||||||
|
@ -31,6 +31,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Pushover
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data["Token"] = options.Token;
|
data["Token"] = options.Token;
|
||||||
data["UserToken"] = options.UserToken;
|
data["UserToken"] = options.UserToken;
|
||||||
if (!string.IsNullOrEmpty(options.Device))
|
if (!string.IsNullOrEmpty(options.Device))
|
||||||
|
@ -36,6 +36,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Slack
|
|||||||
throw new ArgumentException(nameof(options.WebhookUri));
|
throw new ArgumentException(nameof(options.WebhookUri));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data["SlackUsername"] = options.Username;
|
data["SlackUsername"] = options.Username;
|
||||||
data["SlackIconUrl"] = options.IconUrl;
|
data["SlackIconUrl"] = options.IconUrl;
|
||||||
|
|
||||||
|
@ -25,6 +25,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Smtp
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (options.UserFilter.Length != 0
|
||||||
|
&& data.TryGetValue("UserId", out var userIdObj)
|
||||||
|
&& userIdObj is Guid userId)
|
||||||
|
{
|
||||||
|
if (Array.IndexOf(options.UserFilter, userId) == -1)
|
||||||
|
{
|
||||||
|
_logger.LogDebug("UserId {UserId} not found in user filter, ignoring event", userId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var message = new MimeMessage();
|
var message = new MimeMessage();
|
||||||
message.From.Add(new MailboxAddress(options.SenderAddress, options.SenderAddress));
|
message.From.Add(new MailboxAddress(options.SenderAddress, options.SenderAddress));
|
||||||
message.To.Add(new MailboxAddress(options.ReceiverAddress, options.ReceiverAddress));
|
message.To.Add(new MailboxAddress(options.ReceiverAddress, options.ReceiverAddress));
|
||||||
|
Loading…
Reference in New Issue
Block a user