Skip to content

Commit

Permalink
Pull request fix ?
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoSinkin committed Jun 3, 2024
1 parent 5b94f96 commit bf0a54d
Show file tree
Hide file tree
Showing 12 changed files with 609 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.projectforge.framework.persistence.user.entities.PFUserDO
import org.projectforge.framework.time.TimeNotation
import java.util.*

@Suppress("NAME_SHADOWING")
class User(
id: Int? = null,
displayName: String? = null,
Expand All @@ -57,7 +58,6 @@ class User(
var timeZone: String? = null,
var locale: Locale? = null,
var dateFormat: String? = null,
var excelDateFormat: String? = null,
var timeNotation: TimeNotation? = null,
var personalPhoneIdentifiers: String? = null,
var assignedGroups: MutableList<Group>? = null,
Expand Down Expand Up @@ -238,6 +238,10 @@ class User(
users?.forEach { it.displayName = userService.getUser(it.id)?.displayName }
}

fun restoreEmails(users: List<User>?, userService: UserService) {
users?.forEach { it.email = userService.getUser(it.id)?.email }
}

/**
* Converts csv of user ids to list of user.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Poll(
var deadline: LocalDate? = null,
var state: PollDO.State? = PollDO.State.RUNNING,
var questionType: String? = null,
var customemailsubject: String? = null,
var customemailcontent: String? = null,
var prequestionType: String? = null,
var inputFields: MutableList<Question>? = mutableListOf(),
var fullAccessGroups: List<Group>? = null,
var fullAccessUsers: List<User>? = null,
Expand Down Expand Up @@ -77,4 +80,4 @@ class Poll(
fun isFinished(): Boolean {
return state == PollDO.State.FINISHED
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package org.projectforge.rest.poll
import org.projectforge.business.poll.PollDO
import org.projectforge.business.poll.PollDao
import org.projectforge.business.poll.PollResponseDao
import org.projectforge.business.user.service.UserService
import org.projectforge.framework.i18n.translateMsg
import org.projectforge.mail.MailAttachment
import org.projectforge.rest.poll.excel.ExcelExport
Expand Down Expand Up @@ -54,19 +55,23 @@ class PollCronJobs {
@Autowired
private lateinit var exporter: ExcelExport

@Autowired
private lateinit var userService: UserService

private val log: Logger = LoggerFactory.getLogger(PollCronJobs::class.java)

/**
* Cron job for daily stuff
*/

@Scheduled(cron = "0 0 1 * * *") // 1am everyday
@Scheduled(cron = "0 0 */12 * * *") //Alle 12 Stunden
fun dailyCronJobs() {
log.info("Start daily cron jobs")
cronDeletePolls()
cronEndPolls()
}


/**
* Method to end polls after deadline
*/
Expand Down Expand Up @@ -94,12 +99,12 @@ class PollCronJobs {
return excel
}
}
// add all attendees mails
val owner = userService.getUser(poll.owner?.id)
val mailTo: ArrayList<String> =
ArrayList(poll.attendees?.map { it.email }?.mapNotNull { it } ?: emptyList())
val mailFrom = pollDO.owner?.email.toString()
val mailSubject = translateMsg("poll.mail.ended.subject")
val mailContent = translateMsg("poll.mail.ended.content", pollDO.title, pollDO.owner?.displayName)
val mailSubject = translateMsg("poll.mail.endedafterdeadline.subject", poll.title)
val mailContent = translateMsg("poll.mail.endedafterdeadline.content", pollDO.title, owner?.displayName, )

pollDao.internalSaveOrUpdate(pollDO)
log.info("Set state of poll (${pollDO.id}) ${pollDO.title} to FINISHED")
Expand Down Expand Up @@ -153,4 +158,4 @@ class PollCronJobs {
pollDao.internalMarkAsDeleted(poll)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,36 @@ class PollInfoPageRest : AbstractDynamicPageRest() {
layout.add(field)

layout.add(
UIFieldset().add(UILabel("Single Response " + translate("poll.question"))).add(
UIFieldset().add(UILabel(translate("poll.question.singletitel"))).add(
UICol()
.add(
UIReadOnlyField(
"question",
label = "poll.question",
label = "poll.question.single",
value = translate("poll.manual.singleResponse")
)
)
)
)
layout.add(
UIFieldset().add(UILabel("Multiple Response " + translate("poll.question"))).add(
UIFieldset().add(UILabel(translate("poll.question.multititle"))).add(
UICol()
.add(
UIReadOnlyField(
"question",
label = "poll.question",
label = "poll.question.multi",
value = translate("poll.manual.multiResponse")
)
)
)
)
layout.add(
UIFieldset().add(UILabel("Text " + translate("poll.question"))).add(
UIFieldset().add(UILabel(translate("poll.question.texttitle"))).add(
UICol()
.add(
UIReadOnlyField(
"question",
label = "poll.question",
label = "poll.question.text",
value = translate("poll.manual.textQuestion")
)
)
Expand All @@ -121,4 +121,4 @@ class PollInfoPageRest : AbstractDynamicPageRest() {

return FormLayoutData(null, layout, createServerData(request))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,34 +71,53 @@ class PollMailService {
} catch (e: Exception) {
log.error(e.message, e)
}

}

fun getAllMails(poll: Poll): List<String> {
val attendees = poll.attendees
var fullAccessUser = poll.fullAccessUsers?.toMutableList() ?: mutableListOf()
val fullAccessUser = poll.fullAccessUsers?.toMutableList() ?: mutableListOf()
val accessGroupIds = poll.fullAccessGroups?.filter { it.id != null }?.map { it.id!! }?.toIntArray()
val accessUserIds = UserService().getUserIds(groupService.getGroupUsers(accessGroupIds))
val accessUsers = User.toUserList(accessUserIds)

val userList = fullAccessUser
accessUsers?.forEach { user ->
if (fullAccessUser.none { it.id == user.id }) {
fullAccessUser.add(user)
userList.add(user)
}
}

var owner = User.getUser(poll.owner?.id, false)
val owner = User.getUser(poll.owner?.id, false)
if (owner != null) {
fullAccessUser.add(owner)
userList.add(owner)
}
attendees?.forEach {
if (!fullAccessUser.contains(it)) {
fullAccessUser.add(it)
userList.add(it)
}
}

User.restoreDisplayNames(fullAccessUser, userService)
return fullAccessUser.mapNotNull { it.email }
User.restoreDisplayNames(userList, userService)
User.restoreEmails(userList, userService)
return userList.mapNotNull { it.email }
}

fun getAllFullAccessEmails(poll: Poll): List<String> {
val fullAccessUser = poll.fullAccessUsers?.toMutableList() ?: mutableListOf()
poll.fullAccessGroups?.filter { it.id != null }?.map { it.id!! }?.toIntArray()

val userList = fullAccessUser

User.restoreEmails(userList, userService)
return userList.mapNotNull { it.email }
}

}
fun getAllAttendesEmails(poll: Poll): List<String> {
val attendees = poll.attendees

val userList = attendees

User.restoreEmails(userList, userService)
return userList!!.mapNotNull { it.email }
}
}
Loading

0 comments on commit bf0a54d

Please sign in to comment.