Skip to content

Commit

Permalink
fix: Date change fbt logs, publicity change fbt logs, fbt log format
Browse files Browse the repository at this point in the history
  • Loading branch information
Veikkosuhonen committed Dec 1, 2023
1 parent ef0553c commit e751668
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/client/pages/FeedbackTarget/tabs/Logs/Logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useParams } from 'react-router'
import useFeedbackTargetLogs from '../../../../hooks/useFeedbackTargetLogs'
import { LoadingProgress } from '../../../../components/common/LoadingProgress'
import { OpenFeedbackContainer } from '../../../../components/OpenFeedback/OpenFeedback'
import { getLanguageValue } from '../../../../util/languageUtils'

const getLogMessage = data => {
if (!data) {
Expand All @@ -28,12 +29,14 @@ const getLogMessage = data => {
)
}

if (data.enabledPublicQuestions) {
messages = messages.concat(
data.enabledPublicQuestions.length > 0
? `Set answers visible for question '${data.enabledPublicQuestions[0]?.data?.label?.en}'`
: `Set answers hidden for question '${data.disabledPublicQuestions[0]?.data?.label?.en}'`
)
if (data.enabledPublicQuestions?.length) {
const questionName = getLanguageValue(data.enabledPublicQuestions[0]?.data?.label, 'fi')
messages = messages.concat(`Set answers visible for question '${questionName}'`)
}

if (data.disabledPublicQuestions?.length) {
const questionName = getLanguageValue(data.disabledPublicQuestions[0]?.data?.label, 'fi')
messages = messages.concat(`Set answers hidden for question '${questionName}'`)
}

if (data.openImmediately !== undefined) {
Expand All @@ -44,15 +47,13 @@ const getLogMessage = data => {

if (data.createQuestion) {
const { label, content } = data.createQuestion
const question =
(label && (label.en || label.fi || label.sv)) || (content && (content.en || content.fi || content.sv))
const question = getLanguageValue(label, 'fi') || getLanguageValue(content, 'fi')
messages = messages.concat(`Added question '${question}'`)
}

if (data.deleteQuestion) {
const { label, content } = data.deleteQuestion
const question =
(label && (label.en || label.fi || label.sv)) || (content && (content.en || content.fi || content.sv))
const question = getLanguageValue(label, 'fi') || getLanguageValue(content, 'fi')
messages = messages.concat(`Deleted question '${question}'`)
}

Expand Down
3 changes: 2 additions & 1 deletion src/server/services/feedbackTargets/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,14 @@ const update = async ({ feedbackTargetId, user, body }) => {
updates.questions = updatedQuestions
}

await createFeedbackTargetLog(feedbackTarget, updates, user)

Object.assign(feedbackTarget, updates)

// force hooks
feedbackTarget.changed('updatedAt', true)

await feedbackTarget.save()
await createFeedbackTargetLog(feedbackTarget, updates, user)

return feedbackTarget
}
Expand Down
9 changes: 7 additions & 2 deletions src/server/util/auditLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ const createFeedbackTargetLog = async (feedbackTarget, updates, user) => {
const data = {}

if (Array.isArray(updates.publicQuestionIds)) {
const enabledPublicQuestionIds = _.difference(updates.publicQuestionIds, feedbackTarget.publicQuestionIds)
const disabledPublicQuestionIds = _.difference(feedbackTarget.publicQuestionIds, updates.publicQuestionIds)
const enabledPublicQuestionIds = _.difference(updates.publicQuestionIds, feedbackTarget.publicQuestionIds).filter(
qId => (updates.questions?.length ? updates.questions.some(q => q.id === qId) : true)
)

const disabledPublicQuestionIds = _.difference(feedbackTarget.publicQuestionIds, updates.publicQuestionIds).filter(
qId => (updates.questions?.length ? updates.questions.some(q => q.id === qId) : true)
)

if (enabledPublicQuestionIds.length > 0) {
data.enabledPublicQuestions = await Question.findAll({
Expand Down

0 comments on commit e751668

Please sign in to comment.