Enable tagging only in some categories

I’m not so much concerned about the waste of space but found another “issue” with your otherwise very nice JS code. Maybe you can look into this?

We have tag groups that are “staff only” (e.g. hidden tags and system tags) and mandatory tag groups for users per category. Both are linked via “Restrict these tag groups to this category”.

Now, this code only checks if a category allows tags or tag_groups.length>0 or allowed_tags >0 but unfortunately this is always the case as we have those tag groups that are only for staff in the restricted tag groups, too.

Could the code be changed to appreciate the user context and if there are really tags for this specific user available?

 if(category != null) {
                if (
                    category.allow_global_tags == true ||
                    category.allowed_tag_groups.length > 0 ||
                    category.allowed_tags.length > 0
                ) {
                    toggleTagChooser("visible");
                }
            }

Should be possible to count only public in the array category.allowed_tag_groups.length for non-staff users (or are just the names and not the states available in the array?):

public_category.allowed_tag_groups = [public_tag_group.name, staff_only_tag_group.name]
private_category.allowed_tag_groups = [private_tag_group.name, staff_only_tag_group.name]

Ok, update:

In our case, we will inspect the names in allowed_tag_groups and exclude them from the array if currentUser is not staff. But that is a dirty workaround, as I don’t know how to add the user context here (or if this even possible given the current core code, don’t think so).

             var non_staff_tag_groups = category.allowed_tag_groups.filter(filterHidden);
                function filterHidden(value) {
                  if(value.toLowerCase().indexOf("hidden") === -1 && value.toLowerCase().indexOf("system") === -1) return value;
                }
                if (
                    category.allow_global_tags == true ||
                    (category.allowed_tag_groups.length > 0 && this.currentUser.staff) ||
                    (non_staff_tag_groups.length > 0 && !this.currentUser.staff) ||
                    category.allowed_tags.length > 0
                ) {
                    toggleTagChooser("visible");
                }
            }

But this is a dirty hack, the whole tag dropdown in composer should be more contextual via core and should consider all the cases above.

2 Likes