tag prefix fixes
This commit is contained in:
+50
-8
@@ -1301,9 +1301,9 @@ const checkForHandoffs = (task: Task, updates: Partial<Task>): Partial<Task> =>
|
|||||||
for (const tag of updates.tags) {
|
for (const tag of updates.tags) {
|
||||||
// Handle @ prefix in rule matching
|
// Handle @ prefix in rule matching
|
||||||
const rule = store.shareRules.find(r =>
|
const rule = store.shareRules.find(r =>
|
||||||
r.ownerId === currentUserId &&
|
r.ownerId === pb.authStore.model?.id &&
|
||||||
r.type === 'tag' &&
|
r.type === 'tag' &&
|
||||||
(r.tagName === tag || `@${r.tagName}` === tag) &&
|
r.tagName === tag &&
|
||||||
r.share_mode === 'SEND_TASK'
|
r.share_mode === 'SEND_TASK'
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -1650,14 +1650,29 @@ export const syncSystemTagsAndRules = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// --- Sync Bucket System Rule ---
|
// --- Sync Bucket System Rule ---
|
||||||
const bucketRuleExists = normalizedRules.some(r =>
|
const bucketRuleExact = normalizedRules.find(r =>
|
||||||
r.ownerId === currentUserId &&
|
r.ownerId === currentUserId &&
|
||||||
r.targetUserId === currentUserId &&
|
r.targetUserId === currentUserId &&
|
||||||
r.type === 'tag' &&
|
r.type === 'tag' &&
|
||||||
(r.tagName === bucket.name || r.tagName === bucketTagName)
|
r.tagName === bucketTagName
|
||||||
|
);
|
||||||
|
const bucketRuleLegacy = normalizedRules.find(r =>
|
||||||
|
r.ownerId === currentUserId &&
|
||||||
|
r.targetUserId === currentUserId &&
|
||||||
|
r.type === 'tag' &&
|
||||||
|
r.tagName === bucket.name
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!bucketRuleExists) {
|
if (bucketRuleLegacy && !bucketRuleExact) {
|
||||||
|
// Rename legacy rule
|
||||||
|
try {
|
||||||
|
await pb.collection(SHARE_RULES_COLLECTION).update(bucketRuleLegacy.id, { tagName: bucketTagName });
|
||||||
|
setStore("shareRules", r => r.id === bucketRuleLegacy.id, { tagName: bucketTagName });
|
||||||
|
console.log(`Renamed legacy bucket rule: ${bucket.name} -> ${bucketTagName}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to rename legacy bucket rule ${bucket.name}`, e);
|
||||||
|
}
|
||||||
|
} else if (!bucketRuleExact) {
|
||||||
try {
|
try {
|
||||||
await pb.collection(SHARE_RULES_COLLECTION).create({
|
await pb.collection(SHARE_RULES_COLLECTION).create({
|
||||||
ownerId: currentUserId,
|
ownerId: currentUserId,
|
||||||
@@ -1711,14 +1726,29 @@ export const syncSystemTagsAndRules = async () => {
|
|||||||
|
|
||||||
// --- Ensure Self-Rule for Current User (Global Subscription) ---
|
// --- Ensure Self-Rule for Current User (Global Subscription) ---
|
||||||
if (user.id === currentUserId) {
|
if (user.id === currentUserId) {
|
||||||
const selfRuleExists = normalizedRules.some(r =>
|
const selfRuleExact = normalizedRules.find(r =>
|
||||||
r.ownerId === currentUserId &&
|
r.ownerId === currentUserId &&
|
||||||
r.targetUserId === currentUserId &&
|
r.targetUserId === currentUserId &&
|
||||||
r.type === 'tag' &&
|
r.type === 'tag' &&
|
||||||
(r.tagName === originalName || r.tagName === userName)
|
r.tagName === userName
|
||||||
|
);
|
||||||
|
const selfRuleLegacy = normalizedRules.find(r =>
|
||||||
|
r.ownerId === currentUserId &&
|
||||||
|
r.targetUserId === currentUserId &&
|
||||||
|
r.type === 'tag' &&
|
||||||
|
r.tagName === originalName
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!selfRuleExists) {
|
if (selfRuleLegacy && !selfRuleExact) {
|
||||||
|
// Rename legacy self-rule
|
||||||
|
try {
|
||||||
|
await pb.collection(SHARE_RULES_COLLECTION).update(selfRuleLegacy.id, { tagName: userName });
|
||||||
|
setStore("shareRules", r => r.id === selfRuleLegacy.id, { tagName: userName });
|
||||||
|
console.log(`Renamed legacy self-rule: ${originalName} -> ${userName}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`Failed to rename legacy self-rule ${originalName}`, e);
|
||||||
|
}
|
||||||
|
} else if (!selfRuleExact) {
|
||||||
try {
|
try {
|
||||||
const record = await pb.collection(SHARE_RULES_COLLECTION).create({
|
const record = await pb.collection(SHARE_RULES_COLLECTION).create({
|
||||||
ownerId: currentUserId,
|
ownerId: currentUserId,
|
||||||
@@ -1778,6 +1808,18 @@ export const renameTagDefinition = async (oldName: string, newName: string) => {
|
|||||||
const uniqueTags = [...new Set(newTags)];
|
const uniqueTags = [...new Set(newTags)];
|
||||||
updateTask(task.id, { tags: uniqueTags });
|
updateTask(task.id, { tags: uniqueTags });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync Share Rules
|
||||||
|
const rulesWithTag = store.shareRules.filter(r => r.tagName === oldName);
|
||||||
|
for (const rule of rulesWithTag) {
|
||||||
|
try {
|
||||||
|
await pb.collection(SHARE_RULES_COLLECTION).update(rule.id, { tagName: finalName });
|
||||||
|
setStore("shareRules", (r) => r.id === rule.id, { tagName: finalName });
|
||||||
|
console.log(`Synced ShareRule ${rule.id}: ${oldName} -> ${finalName}`);
|
||||||
|
} catch (ruleErr) {
|
||||||
|
console.error(`Failed to sync ShareRule ${rule.id} during tag rename:`, ruleErr);
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Failed to rename tag:", err);
|
console.error("Failed to rename tag:", err);
|
||||||
toast.error("Failed to rename tag.");
|
toast.error("Failed to rename tag.");
|
||||||
|
|||||||
Reference in New Issue
Block a user