Hi everyone!
I need to restrict a user of a specific role from being able to edit a custom field. I made a script in Behaviours which works perfectly in a JIRA Software project, but in JSM this restriction does not work and allows independent editing of the role I define. Is there a specific function or script to make it work in JSM
Thank you very much.
// Campo a controlar
const estadoPortafolio = getFieldById("customfield_11214");
// Obtener contexto del proyecto
const context = await getContext();
const projectId = context.extension.project.id;
// Obtener roles del usuario actual en JSM
const getProjectRoles = await makeRequest(`/rest/api/3/project/${projectId}/roledetails?currentMember=true`);
const roleNames = getProjectRoles.body.map(role => role.name);
// Depurar: Imprimir roles detectados
logger.info(`Roles del usuario en JSM: ${roleNames.join(", ")}`);
// Roles autorizados (¡ajusta los nombres según tu JSM!)
const rolesAutorizados = [
"Administrador de Portafolio",
"Administrators"
];
// Verificar si el usuario tiene un rol autorizado
const usuarioAutorizado = rolesAutorizados.some(rol => roleNames.includes(rol));
// Bloquear el campo si el usuario no está autorizado
if (usuarioAutorizado) {
estadoPortafolio.setReadOnly(false); // Permitir edición
logger.info("Usuario autorizado: Campo habilitado.");
} else {
estadoPortafolio.setReadOnly(true); // Bloquear edición
logger.info("Usuario no autorizado: Campo bloqueado.");
// Si el campo sigue siendo editable, ocúltalo:
estadoPortafolio.setVisible(false);
}