-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from micromata/Release-8.1-SNAPSHOT
Release 8.1 snapshot - Visibility of plugin licensesManagement is now configurable. - Bugfix: TaskServicesRest: access checking: whole task tree were shown while editing time sheets. - Multi selection of employees fixed: Visitorbook and Vacation entries.
- Loading branch information
Showing
19 changed files
with
262 additions
and
129 deletions.
There are no files selected for viewing
84 changes: 0 additions & 84 deletions
84
...ent/src/main/java/org/projectforge/plugins/licensemanagement/LicenseManagementPlugin.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...ent/src/main/kotlin/org/projectforge/plugins/licensemanagement/LicenseManagementPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Project ProjectForge Community Edition | ||
// www.projectforge.org | ||
// | ||
// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com) | ||
// | ||
// ProjectForge is dual-licensed. | ||
// | ||
// This community edition is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License as published | ||
// by the Free Software Foundation; version 3 of the License. | ||
// | ||
// This community edition is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
// Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along | ||
// with this program; if not, see http://www.gnu.org/licenses/. | ||
// | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
package org.projectforge.plugins.licensemanagement | ||
|
||
import org.projectforge.menu.builder.MenuItemDef | ||
import org.projectforge.menu.builder.MenuItemDefId | ||
import org.projectforge.plugins.core.AbstractPlugin | ||
import org.projectforge.plugins.core.PluginAdminService | ||
import org.projectforge.plugins.licensemanagement.rest.LicensePagesRest | ||
import org.projectforge.registry.RegistryEntry | ||
import org.projectforge.security.My2FAShortCut | ||
import org.projectforge.web.WicketSupport | ||
import org.projectforge.web.plugin.PluginWicketRegistrationService | ||
|
||
/** | ||
* @author Kai Reinhard ([email protected]) | ||
*/ | ||
class LicenseManagementPlugin : AbstractPlugin( | ||
PluginAdminService.PLUGIN_LICENSE_MANAGEMENT_ID, | ||
"LicenseManagementPlugin", | ||
"For managing software licenses, keys and usage." | ||
) { | ||
/** | ||
* @see org.projectforge.plugins.core.AbstractPlugin.initialize | ||
*/ | ||
override fun initialize() { | ||
val licenseDao = WicketSupport.get(LicenseDao::class.java) | ||
val pluginWicketRegistrationService = WicketSupport.get( | ||
PluginWicketRegistrationService::class.java | ||
) | ||
registerShortCutValues(My2FAShortCut.FINANCE_WRITE, "WRITE:license;/wa/licenseManagementEdit") | ||
registerShortCutValues(My2FAShortCut.FINANCE_WRITE, "/wa/licenseManagement") | ||
registerShortCutClasses(My2FAShortCut.FINANCE, LicensePagesRest::class.java) | ||
val entry = RegistryEntry( | ||
ID, | ||
LicenseDao::class.java, licenseDao, | ||
"plugins.licensemanagement" | ||
) | ||
// The LicenseDao is automatically available by the scripting engine! | ||
register(entry) | ||
|
||
// Register the web part: | ||
pluginWicketRegistrationService.registerWeb( | ||
ID, | ||
LicenseListPage::class.java, | ||
LicenseEditPage::class.java | ||
) | ||
|
||
val menuItemDef = MenuItemDef( | ||
ID, "plugins.licensemanagement.menu", | ||
checkAccess = { | ||
LicensePluginService.instance.hasAccess() | ||
}) | ||
// Register the menu entry as sub menu entry of the misc menu: | ||
pluginWicketRegistrationService.registerMenuItem( | ||
MenuItemDefId.MISC, menuItemDef, | ||
LicenseListPage::class.java | ||
) | ||
|
||
// Define the access management: | ||
registerRight(LicenseManagementRight()) | ||
|
||
// All the i18n stuff: | ||
addResourceBundle(RESOURCE_BUNDLE_NAME) | ||
} | ||
|
||
companion object { | ||
const val ID: String = "licenseManagement" | ||
|
||
const val RESOURCE_BUNDLE_NAME: String = "LicenseManagementI18nResources" | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
...gement/src/main/kotlin/org/projectforge/plugins/licensemanagement/LicensePluginService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Project ProjectForge Community Edition | ||
// www.projectforge.org | ||
// | ||
// Copyright (C) 2001-2025 Micromata GmbH, Germany (www.micromata.com) | ||
// | ||
// ProjectForge is dual-licensed. | ||
// | ||
// This community edition is free software; you can redistribute it and/or | ||
// modify it under the terms of the GNU General Public License as published | ||
// by the Free Software Foundation; version 3 of the License. | ||
// | ||
// This community edition is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
// Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License along | ||
// with this program; if not, see http://www.gnu.org/licenses/. | ||
// | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
package org.projectforge.plugins.licensemanagement | ||
|
||
import jakarta.annotation.PostConstruct | ||
import mu.KotlinLogging | ||
import org.projectforge.business.user.UserGroupCache | ||
import org.projectforge.framework.persistence.user.api.ThreadLocalUserContext | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
|
||
private val log = KotlinLogging.logger {} | ||
|
||
@Service | ||
class LicensePluginService { | ||
/** | ||
* List of groups that are allowed to manage and see licenses. | ||
* ALL for all users, empty/NONE for no user, or csv list of group pk's or group names. | ||
*/ | ||
@Value("\${projectforge.plugins.license.allowedGroups}") | ||
var allowedGroups: String? = null | ||
|
||
@Autowired | ||
private lateinit var userGroupCache: UserGroupCache | ||
|
||
private var allowedGroupIds = emptyList<Long>() | ||
|
||
private var allUsersAllowed = false | ||
|
||
@PostConstruct | ||
fun postConstruct() { | ||
instance = this | ||
run { | ||
allowedGroups?.split(",;")?.forEach { entry -> | ||
val trimmed = entry.trim() | ||
if (trimmed.isEmpty()) { | ||
return@forEach | ||
} else if (trimmed.equals("ALL", ignoreCase = true)) { | ||
allowedGroupIds = emptyList() | ||
allUsersAllowed = true | ||
return@run // No need to continue. break | ||
} else if (trimmed.equals("NONE", ignoreCase = true)) { | ||
allowedGroupIds = emptyList() | ||
return@run // No need to continue. break | ||
} | ||
val groupId = trimmed.toLongOrNull() | ||
if (groupId != null) { | ||
userGroupCache.getGroup(groupId)?.id.let { id -> | ||
if (id != null) { | ||
allowedGroupIds += id | ||
} else { | ||
log.warn("No group with id $groupId found for license management in projectforge.properties:projectforge.plugins.license.allowedGroups=$allowedGroups") | ||
} | ||
} | ||
allowedGroupIds += groupId | ||
} else { | ||
userGroupCache.getGroupByName(trimmed)?.id.let { id -> | ||
if (id != null) { | ||
allowedGroupIds += id | ||
} else { | ||
log.warn("No group with name '$trimmed' found for license management in projectforge.properties:projectforge.plugins.license.allowedGroups=$allowedGroups") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (allUsersAllowed) { | ||
log.info { "Allowed groups for license management: ALL users." } | ||
} else if (allowedGroupIds.isEmpty()) { | ||
log.info { "No groups allowed for license management (not visible and usable for any user)." } | ||
} else { | ||
log.info { | ||
"Allowed groups for license management: ${ | ||
allowedGroupIds.joinToString { | ||
userGroupCache.getGroup( | ||
it | ||
)?.name ?: "???" | ||
} | ||
}" | ||
} | ||
} | ||
} | ||
|
||
fun hasAccess(): Boolean { | ||
if (allUsersAllowed) { | ||
return true | ||
} | ||
userGroupCache.getUserGroups(ThreadLocalUserContext.requiredLoggedInUser)?.forEach { groupId -> | ||
if (allowedGroupIds.contains(groupId)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
lateinit var instance: LicensePluginService | ||
private set | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.