Skip to content

Commit

Permalink
PFUserDO.getRight removed (isn't stable, rights are lazy fetched)
Browse files Browse the repository at this point in the history
  • Loading branch information
kreinhard committed Jan 30, 2025
1 parent a199925 commit fb6eec1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ import org.projectforge.common.anots.PropertyInfo
import org.projectforge.framework.DisplayNameCapable
import org.projectforge.framework.configuration.Configuration
import org.projectforge.framework.json.IdsOnlySerializer
import org.projectforge.framework.persistence.api.HibernateUtils
import org.projectforge.framework.persistence.api.IUserRightId
import org.projectforge.framework.persistence.entities.DefaultBaseDO
import org.projectforge.framework.persistence.history.NoHistory
import org.projectforge.framework.time.PFDateTime
Expand Down Expand Up @@ -413,18 +411,6 @@ open class PFUserDO : DefaultBaseDO(), DisplayNameCapable {
return this
}

/**
* Attention: rights may not be fully initialized!
*/
@Transient
fun getRight(rightId: IUserRightId): UserRightDO? {
return if (HibernateUtils.isFullyInitialized(this.rights)) {
this.rights?.find { it.rightIdString == rightId.id }
} else {
null
}
}

/**
* @return true only and only if the user isn't either deleted nor deactivated, otherwise false.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package org.projectforge.business.fibu

import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.projectforge.business.test.AbstractTestBase
import org.projectforge.business.user.GroupDao
import org.projectforge.business.user.UserRightDao
import org.projectforge.business.user.UserRightId
Expand All @@ -36,7 +37,6 @@ import org.projectforge.framework.persistence.user.entities.PFUserDO
import org.projectforge.framework.persistence.user.entities.UserRightDO
import org.projectforge.framework.time.PFDay.Companion.now
import org.projectforge.framework.time.PFDay.Companion.withDate
import org.projectforge.business.test.AbstractTestBase
import org.springframework.beans.factory.annotation.Autowired
import java.io.Serializable
import java.math.BigDecimal
Expand Down Expand Up @@ -280,10 +280,11 @@ class AuftragDaoTest : AbstractTestBase() {
}
}
persistenceService.runInTransaction { _ ->
val user = logonUser!!
user = logonUser!!
logon(TEST_ADMIN_USER)
val right = user.getRight(UserRightId.PM_ORDER_BOOK)!!
right.value = UserRightValue.READWRITE // Full access

val right = user.rights?.find { it.rightIdString == UserRightId.PM_ORDER_BOOK.id }
right!!.value = UserRightValue.READWRITE // Full access
userRightDao.update(right)
logon(user)
auftragDao.find(auftragId, attached = true) // Attached is important, otherwise deadlock.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.projectforge.framework.persistence.user.entities.UserRightDO
import org.projectforge.framework.time.PFDateTime.Companion.withDate
import org.projectforge.framework.time.PFDay
import org.projectforge.business.test.AbstractTestBase
import org.projectforge.business.timesheet.TimesheetReferenceListTest.Companion.user
import org.springframework.beans.factory.annotation.Autowired
import java.io.Serializable
import java.math.BigDecimal
Expand Down Expand Up @@ -158,7 +159,7 @@ class HRPlanningTest : AbstractTestBase() {
logon(TEST_ADMIN_USER)
// split
user1 = userService.find(user1.id, false)
val userRight = user1.getRight(UserRightId.PM_HR_PLANNING)
val userRight = user1.rights?.find { it.rightIdString == UserRightId.PM_HR_PLANNING.id }
userRight!!.value = UserRightValue.READWRITE
userRightDao.update(userRight)
logon(user1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class CandHHistoryTest : AbstractTestBase() {
}

user.addRight(UserRightDO(UserRightId.PM_ORDER_BOOK, UserRightValue.PARTLYREADWRITE))
user.getRight(UserRightId.ORGA_OUTGOING_MAIL).let { right ->
user.rights?.find { it.rightIdString == UserRightId.ORGA_OUTGOING_MAIL.id }.let { right ->
right!!.value = UserRightValue.READONLY
}
userRightDao.insertOrUpdate(user.rights!!, checkAccess = false)
Expand Down

0 comments on commit fb6eec1

Please sign in to comment.