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
@ -54,6 +54,13 @@
|
||||
</label>
|
||||
</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">
|
||||
<div class="inputContainer">
|
||||
<input is="emby-input" type="text" data-name="txtWebhookName" required="required" label="Webhook Name:"/>
|
||||
@ -68,6 +75,11 @@
|
||||
<div data-name="notificationTypeContainer">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>User Filter:</label>
|
||||
<div data-name="userFilterContainer">
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label>Item Type:</label>
|
||||
<label class="checkboxContainer">
|
||||
|
@ -78,13 +78,49 @@
|
||||
},
|
||||
get: function (container) {
|
||||
const notificationTypes = [];
|
||||
const checkboxes = container.querySelectorAll('[data-name=notificationTypeValue]:checked')
|
||||
const checkboxes = container.querySelectorAll('[data-name=notificationTypeValue]:checked');
|
||||
for (const checkbox of checkboxes) {
|
||||
notificationTypes.push(checkbox.dataset.value);
|
||||
}
|
||||
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: {
|
||||
template: document.querySelector("#template-base"),
|
||||
addConfig: function (template, destinationType, destinationName) {
|
||||
@ -130,6 +166,9 @@
|
||||
|
||||
const notificationTypeContainer = element.querySelector("[data-name=notificationTypeContainer]");
|
||||
Webhook.notificationType.create(notificationTypeContainer, config.NotificationTypes);
|
||||
|
||||
const userFilterContainer = element.querySelector("[data-name=userFilterContainer]");
|
||||
Webhook.userFilter.create(userFilterContainer, config.UserFilter);
|
||||
},
|
||||
getConfig: function (element) {
|
||||
const config = {};
|
||||
@ -147,7 +186,9 @@
|
||||
|
||||
config.NotificationTypes = [];
|
||||
config.NotificationTypes = Webhook.notificationType.get(element);
|
||||
console.log(config.NotificationTypes);
|
||||
|
||||
config.UserFilter = [];
|
||||
config.UserFilter = Webhook.userFilter.get(element);
|
||||
return config;
|
||||
}
|
||||
},
|
||||
@ -447,7 +488,7 @@
|
||||
return config;
|
||||
}
|
||||
},
|
||||
init: function () {
|
||||
init: async function () {
|
||||
// Add click handlers
|
||||
Webhook.discord.btnAdd.addEventListener("click", Webhook.discord.addConfig);
|
||||
Webhook.generic.btnAdd.addEventListener("click", Webhook.generic.addConfig);
|
||||
@ -458,6 +499,7 @@
|
||||
Webhook.smtp.btnAdd.addEventListener("click", Webhook.smtp.addConfig);
|
||||
document.querySelector("#saveConfig").addEventListener("click", Webhook.saveConfig);
|
||||
|
||||
await Webhook.userFilter.populate();
|
||||
Webhook.loadConfig();
|
||||
},
|
||||
removeConfig: function (e) {
|
||||
@ -569,7 +611,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
view.addEventListener("viewshow", function (e) {
|
||||
Webhook.init();
|
||||
view.addEventListener("viewshow", async function () {
|
||||
await Webhook.init();
|
||||
});
|
||||
}
|
||||
|
@ -72,6 +72,11 @@ namespace Jellyfin.Plugin.Webhook.Destinations
|
||||
/// </summary>
|
||||
public string? Template { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the webhook user filter.
|
||||
/// </summary>
|
||||
public Guid[] UserFilter { get; set; } = Array.Empty<Guid>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the compiled handlebars template.
|
||||
/// </summary>
|
||||
|
@ -37,6 +37,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Discord
|
||||
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.
|
||||
data["MentionType"] = GetMentionType(options.MentionType);
|
||||
if (!string.IsNullOrEmpty(options.EmbedColor))
|
||||
|
@ -34,6 +34,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Generic
|
||||
{
|
||||
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)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
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.
|
||||
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.Mime;
|
||||
using System.Text;
|
||||
@ -32,6 +33,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Pushbullet
|
||||
{
|
||||
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["PushbulletDeviceId"] = options.DeviceId;
|
||||
data["PushbulletChannel"] = options.Channel;
|
||||
|
@ -31,6 +31,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Pushover
|
||||
{
|
||||
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["UserToken"] = options.UserToken;
|
||||
if (!string.IsNullOrEmpty(options.Device))
|
||||
|
@ -36,6 +36,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Slack
|
||||
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["SlackIconUrl"] = options.IconUrl;
|
||||
|
||||
|
@ -25,6 +25,17 @@ namespace Jellyfin.Plugin.Webhook.Destinations.Smtp
|
||||
{
|
||||
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();
|
||||
message.From.Add(new MailboxAddress(options.SenderAddress, options.SenderAddress));
|
||||
message.To.Add(new MailboxAddress(options.ReceiverAddress, options.ReceiverAddress));
|
||||
|
Loading…
Reference in New Issue
Block a user