-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic DegreeSite creation upon Degree entity creation #25
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,24 +18,46 @@ | |
*/ | ||
package org.fenixedu.learning.domain.degree; | ||
|
||
import static com.google.common.base.Joiner.on; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import org.fenixedu.academic.domain.Degree; | ||
import org.fenixedu.academic.domain.accessControl.CoordinatorGroup; | ||
import org.fenixedu.bennu.core.domain.Bennu; | ||
import org.fenixedu.bennu.core.groups.DynamicGroup; | ||
import org.fenixedu.bennu.core.i18n.BundleUtil; | ||
import org.fenixedu.bennu.core.util.CoreConfiguration; | ||
import org.fenixedu.bennu.portal.domain.MenuContainer; | ||
import org.fenixedu.bennu.portal.domain.PortalConfiguration; | ||
import org.fenixedu.cms.domain.CMSFolder; | ||
import org.fenixedu.cms.domain.Category; | ||
import org.fenixedu.cms.domain.wraps.Wrap; | ||
import org.fenixedu.commons.i18n.LocalizedString; | ||
import pt.ist.fenixframework.DomainObject; | ||
import org.joda.time.DateTime; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
import pt.ist.fenixframework.DomainObject; | ||
|
||
public class DegreeSite extends DegreeSite_Base { | ||
|
||
public DegreeSite(Degree degree) { | ||
super(); | ||
checkNotNull(degree); | ||
setDegree(degree); | ||
|
||
setFolder(folderForPath(PortalConfiguration.getInstance().getMenu(), "degrees")); | ||
setSlug(on("-").join(degree.getSigla(), degree.getExternalId())); | ||
|
||
setCreationDate(new DateTime()); | ||
setCanAdminGroup(DynamicGroup.get("managers")); | ||
setCanPostGroup(CoordinatorGroup.get(degree)); | ||
|
||
setPublished(true); | ||
setBennu(Bennu.getInstance()); | ||
degree.setSiteUrl(getFullUrl()); | ||
} | ||
|
||
@Override | ||
|
@@ -72,4 +94,19 @@ public Stream<Wrap> getCategoriesToShow() { | |
return Stream.of(categoryForSlug("announcement")).filter(Objects::nonNull).map(Category::makeWrap); | ||
} | ||
|
||
private CMSFolder folderForPath(MenuContainer parent, String path) { | ||
|
||
LocalizedString.Builder description = new LocalizedString.Builder(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simply use |
||
CoreConfiguration | ||
.supportedLocales() | ||
.stream() | ||
.forEach( | ||
l -> description.with(l, | ||
BundleUtil.getString("resources.FenixEduLearningResources", l, "label.degree.folder.description"))); | ||
|
||
return parent.getOrderedChild().stream().filter(item -> item.getPath().equals(path)) | ||
.map(item -> item.getAsMenuFunctionality().getCmsFolder()).findAny() | ||
.orElseGet(() -> new CMSFolder(parent, path, description.build())); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,11 +31,12 @@ | |
import org.fenixedu.academic.domain.accessControl.StudentSharingDegreeOfCompetenceOfExecutionCourseGroup; | ||
import org.fenixedu.academic.domain.accessControl.StudentSharingDegreeOfExecutionCourseGroup; | ||
import org.fenixedu.academic.domain.accessControl.TeacherGroup; | ||
import org.fenixedu.academic.domain.accessControl.TeacherResponsibleOfExecutionCourseGroup; | ||
import org.fenixedu.bennu.core.domain.Bennu; | ||
import org.fenixedu.bennu.core.groups.AnyoneGroup; | ||
import org.fenixedu.bennu.core.groups.DynamicGroup; | ||
import org.fenixedu.bennu.core.groups.Group; | ||
import org.fenixedu.bennu.core.groups.LoggedGroup; | ||
import org.fenixedu.bennu.core.groups.NobodyGroup; | ||
import org.fenixedu.bennu.core.i18n.BundleUtil; | ||
import org.fenixedu.bennu.core.util.CoreConfiguration; | ||
import org.fenixedu.bennu.portal.domain.MenuContainer; | ||
|
@@ -44,6 +45,7 @@ | |
import org.fenixedu.cms.domain.Category; | ||
import org.fenixedu.cms.domain.wraps.Wrap; | ||
import org.fenixedu.commons.i18n.LocalizedString; | ||
import org.joda.time.DateTime; | ||
|
||
import pt.ist.fenixframework.Atomic; | ||
import pt.ist.fenixframework.DomainObject; | ||
|
@@ -56,13 +58,16 @@ public class ExecutionCourseSite extends ExecutionCourseSite_Base { | |
public ExecutionCourseSite(ExecutionCourse executionCourse) { | ||
checkNotNull(executionCourse); | ||
setExecutionCourse(executionCourse); | ||
setPublished(true); | ||
|
||
setFolder(folderForPath(PortalConfiguration.getInstance().getMenu(), "courses")); | ||
setSlug(on("-").join(getExecutionCourse().getSigla(), getExecutionCourse().getExternalId())); | ||
setCanAdminGroup(NobodyGroup.get()); | ||
setCanPostGroup(NobodyGroup.get()); | ||
setBennu(Bennu.getInstance()); | ||
|
||
setCreationDate(new DateTime()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creation date shouldn't be set here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment leaves everything to be guessed, again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creation date is already set at the Site constructor. Calling the super() method should set that for you, so there is no need to set it here again. |
||
setCanAdminGroup(DynamicGroup.get("managers")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beware that setting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the "canPostGroup" to ExecutionCourse responsibles. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have some concerns settings this to manager. All the managers will be have access to any execution course page. |
||
setCanPostGroup(TeacherResponsibleOfExecutionCourseGroup.get(executionCourse)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now this has no effect, and may cause problems. We don't want to give teacher this interface right now. Adding this at this junction should be done on another place and not here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand your comment refers to L67. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, for now lets put it at Nobody, and when we have the access control on CMS revisit this problem. What I would suggest doing on your installations is setting this to the appropriate access control using signals or scripts. |
||
|
||
setPublished(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this changed place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As before, I'll guess you are referring to L69. Line 69 changing places must have been simply the consequence of code editing. Despite always being an interesting line number, it's barely even worth mentioning, and certainly not worth raising an issue around it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, no problem. I wasn't raising an issue, I was just wondering why. |
||
setBennu(Bennu.getInstance()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line must be back ported to CMS, most likely this doesn't make sense to be made on this place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which line? You are referring to a whole diff block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only Line 70. Attaching the instance to Bennu should be done within the CMS. This is a bug, and should be corrected at CMS. But for now lets leave it here, because this isn't fixed yet on the other module |
||
executionCourse.setSiteUrl(getFullUrl()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that folders are optional in the CMS, it does not make sense to blow up if that particular folder is not found.
One might want not to organize degree sites in folders (or even set them up in a custom, on different path), so I think it would just be better to do nothing in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, like ExecutionCourseSite example, if parent folder not found, now is created a new one.