[MGNLFORUM-237] Deleting a forum and creating a new one with same name throws exception Created: 19/Feb/14  Updated: 24/Feb/14  Resolved: 20/Feb/14

Status: Closed
Project: Forum (closed)
Component/s: None
Affects Version/s: 3.3
Fix Version/s: 3.3

Type: Bug Priority: Neutral
Reporter: Roman Kovařík Assignee: Christoph Meier
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Template:
Acceptance criteria:
Empty
Date of First Response:

 Description   

Steps to reproduce:

  1. create new forum
  2. delete this forum
  3. add new forum with same name
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Role with name forum-1-user already exists.
	at info.magnolia.module.forum.DefaultForumManager$1.doExec(DefaultForumManager.java:168)
	at info.magnolia.context.MgnlContext$VoidOp.exec(MgnlContext.java:414)
	at info.magnolia.context.MgnlContext$VoidOp.exec(MgnlContext.java:411)
	at info.magnolia.context.MgnlContext.doInSystemContext(MgnlContext.java:385)
	at info.magnolia.context.MgnlContext.doInSystemContext(MgnlContext.java:371)
	at info.magnolia.module.forum.DefaultForumManager.createForumRoles(DefaultForumManager.java:154)
	at info.magnolia.module.forum.DefaultForumManager.createForum(DefaultForumManager.java:145)
	at info.magnolia.module.forum.app.action.SaveDialogNewForumAction.execute(SaveDialogNewForumAction.java:75)
	at info.magnolia.ui.api.action.AbstractActionExecutor.execute(AbstractActionExecutor.java:74)
	... 110 more
Caused by: java.lang.IllegalArgumentException: Role with name forum-1-user already exists.
	at info.magnolia.cms.security.MgnlRoleManager.validateRoleName(MgnlRoleManager.java:254)
	at info.magnolia.cms.security.MgnlRoleManager.createRole(MgnlRoleManager.java:98)
	at info.magnolia.cms.security.MgnlRoleManager.createRole(MgnlRoleManager.java:87)
	at info.magnolia.module.forum.DefaultForumManager$1.doExec(DefaultForumManager.java:159)
	... 118 more


 Comments   
Comment by Christoph Meier [ 19/Feb/14 ]

Automatically deleting roles seems risky since user may have references to these roles.
The "old forum version" (M4.5) doesn't delete them automatically neither; but it doesnt't show an exception on the UI when the ForumMangager tries to add new roles which actually already exist.

This said, the current behaviour is correct.

The "not so nice thing" is the error-message which pops up, it says "Action execution failed for action: commit" ...
... instead it should tell smthng. like "Role with name forum-xxx-user already exists" ... which actually is the root-cause ... but this seems then more a "framework problem".
In such a case, the forum is created but the workspace must be refreshed to show it! again, ugly.
But since creation of the forum-node and the role-nodes are done in different workspace (without something like a "common transaction") it is like it is.

Comment by Roman Kovařík [ 20/Feb/14 ]

In this case, info.magnolia.module.forum.DefaultForumManager.createForumRoles(Content) should check if the role doesn't exists already.

Comment by Roman Kovařík [ 20/Feb/14 ]
  1. No need to catch UnsupportedOperationException since its RuntimeException.
  2. Please add unit test to check if it really fixes the issue (you can copy info.magnolia.module.forum.DefaultForumManagerTest.testCreatingForumShouldCreateAdhocRoles()) and the only change will be that you call defaultForumManager.createForum() two times.
Generated at Mon Feb 12 02:02:00 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.