Korjaa admin-roolitarkistukset käyttämään isCurrentUserAdmin()

Kaikki kohdat jotka tarkistivat currentUser.role === 'admin' on päivitetty
käyttämään isCurrentUserAdmin()-funktiota, joka tarkistaa yrityskohtaisen
company_role-arvon. Korjaa mm. tehtävien lisäysnapin katoamisen.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 21:20:16 +02:00
parent 68c9075676
commit 5d17381f58

View File

@@ -2719,7 +2719,7 @@ async function loadCompanyUsers(companyId) {
return `<label style="display:flex;align-items:center;gap:0.5rem;padding:0.4rem 0;cursor:pointer;">
<input type="checkbox" class="company-user-cb" data-user-id="${u.id}" ${hasAccess ? 'checked' : ''} onchange="toggleCompanyUser('${u.id}','${companyId}',this.checked)">
<strong>${esc(u.nimi || u.username)}</strong>
<span style="color:#888;font-size:0.85rem;">(${u.username}) — ${u.role === 'superadmin' ? 'Pääkäyttäjä' : (u.role === 'admin' ? 'Yritysadmin' : 'Käyttäjä')}</span>
<span style="color:#888;font-size:0.85rem;">(${u.username}) — ${u.role === 'superadmin' ? 'Pääkäyttäjä' : ((u.company_roles || {})[companyId] === 'admin' ? 'Admin' : 'Käyttäjä')}</span>
</label>`;
}).join('');
} catch (e) { console.error(e); }
@@ -3625,7 +3625,7 @@ async function loadGuides() {
populateGuideCategoryFilter();
renderGuidesList();
showGuideListView();
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
document.getElementById('btn-add-guide').style.display = isAdmin ? '' : 'none';
document.getElementById('btn-manage-guide-cats').style.display = isAdmin ? '' : 'none';
} catch (e) { console.error(e); }
@@ -3715,7 +3715,7 @@ async function openGuideRead(id) {
document.getElementById('guide-read-tags').innerHTML = tags.length > 0
? tags.map(t => `<span class="guide-tag">${esc(t.trim())}</span>`).join(' ')
: '';
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
document.getElementById('guide-read-actions').style.display = isAdmin ? 'block' : 'none';
showGuideReadView();
} catch (e) { alert(e.message); }
@@ -4007,9 +4007,8 @@ async function loadTodos() {
renderTasksList();
renderFeaturesList();
populateTodoAssignedFilter();
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const btnTask = document.getElementById('btn-add-task');
if (btnTask) btnTask.style.display = isAdmin ? '' : 'none';
if (btnTask) btnTask.style.display = isCurrentUserAdmin() ? '' : 'none';
} catch (e) { console.error('loadTodos:', e); }
}
@@ -4127,7 +4126,7 @@ async function openTaskRead(id) {
currentTodoId = id;
try {
const t = await apiCall('todo_detail&id=' + id);
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
document.getElementById('task-read-title').textContent = t.title;
document.getElementById('task-read-meta').innerHTML = `Luoja: ${esc(t.created_by)} &nbsp;|&nbsp; Luotu: ${(t.luotu||'').slice(0,10)} ${t.muokattu ? '&nbsp;|&nbsp; Muokattu: ' + t.muokattu.slice(0,10) : ''}`;
document.getElementById('task-read-badges').innerHTML = `
@@ -4297,7 +4296,7 @@ async function openFeatureRead(id) {
currentTodoId = id;
try {
const t = await apiCall('todo_detail&id=' + id);
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
const isOwner = t.created_by === currentUser?.username;
document.getElementById('feature-read-title').textContent = t.title;
document.getElementById('feature-read-meta').innerHTML = `Ehdottaja: ${esc(t.created_by)} &nbsp;|&nbsp; ${(t.luotu||'').slice(0,10)}`;
@@ -4358,7 +4357,7 @@ document.getElementById('feature-form')?.addEventListener('submit', async (e) =>
function renderTodoComments(comments, prefix) {
const list = document.getElementById(prefix + '-comments-list');
if (!list) return;
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
list.innerHTML = comments.length ? comments.map(c => `<div class="todo-comment">
<div class="todo-comment-meta">${esc(c.author)} &nbsp;·&nbsp; ${(c.luotu||'').replace('T',' ').slice(0,16)}</div>
<div style="white-space:pre-wrap;">${esc(c.body)}</div>
@@ -4758,7 +4757,7 @@ function renderDocReadView() {
document.getElementById('doc-read-description').textContent = d.description || '';
// Admin-napit
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
document.getElementById('btn-doc-delete').style.display = isAdmin ? '' : 'none';
// Latausnappi - piilota jos ei versioita
@@ -4982,7 +4981,7 @@ function renderLaitetilaReadView() {
document.getElementById('laitetila-read-osoite').textContent = t.osoite ? '📍 ' + t.osoite : '';
document.getElementById('laitetila-read-kuvaus').textContent = t.kuvaus || '';
const isAdmin = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdmin = isCurrentUserAdmin();
document.getElementById('btn-laitetila-delete').style.display = isAdmin ? '' : 'none';
// Erota kuvat ja muut tiedostot
@@ -5138,7 +5137,7 @@ function applyModules(modules) {
}
// Jos tyhjä array → kaikki moduulit päällä (fallback)
const enabled = (modules && modules.length > 0) ? modules : ALL_MODULES;
const isAdminUser = currentUser?.role === 'admin' || currentUser?.role === 'superadmin';
const isAdminUser = isCurrentUserAdmin();
ALL_MODULES.forEach(mod => {
const tabBtn = document.querySelector(`.tab[data-tab="${mod}"]`);
if (tabBtn) {