Skip to content

Commit

Permalink
SAK-46302 Lessons add group visibility to forums (sakaiproject#9856)
Browse files Browse the repository at this point in the history
- Removing unused methods
- I'm getting exceptions locally StaleObject exceptions when modifying
forums/topics (even outside of Lessons) but it seems it's not happening
on nightly...
  • Loading branch information
bgarciaentornos authored Sep 27, 2021
1 parent e0a1d19 commit 3210cdf
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 723 deletions.
2 changes: 0 additions & 2 deletions lessonbuilder/NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class LessonEntity
Object actual
int type; actual underlying Sakai type
String reference
static boolean addEntityControl(String ref, String siteId, String groupId) throws IOException {
static boolean removeEntityControl(String ref, String siteId, String groupId) throws IOException {
static LessonEntity getEntity(ref)
String getTitle
String getUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -487,23 +487,6 @@ public Object readSqlResultRecord(ResultSet result)

}

// access control
// no longer used, so there's no way to test them
public boolean addEntityControl(String siteId, final String groupId) throws IOException {
return false;

}

public boolean removeEntityControl(String siteId, String groupId) throws IOException {
return false;
}

// submission
// do we need the data from submission?
public boolean needSubmission(){
return true;
}

public Double toDouble(Object f) {
if (f instanceof Double)
return (Double)f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,6 @@ public Date getDueDate() {
return assessment.getDates().getDueDate();
}

// the following methods all take references. So they're in effect static.
// They ignore the entity from which they're called.
// The reason for not making them a normal method is that many of the
// implementations seem to let you set access control and find submissions
// from a reference, without needing the actual object. So doing it this
// way could save some database activity

// access control
public boolean addEntityControl(String siteId, String groupId) throws IOException {
return true;
}

public boolean removeEntityControl(String siteId, String groupId) throws IOException {
return true;
}

// submission
// do we need the data from submission?
public boolean needSubmission(){
return true;
}

public LessonSubmission getSubmission(String user) {
if (assessment == null)
assessment = getAssessment(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@
import org.sakaiproject.lessonbuildertool.service.LessonSubmission;
import org.sakaiproject.lessonbuildertool.tool.beans.SimplePageBean;
import org.sakaiproject.lessonbuildertool.tool.beans.SimplePageBean.UrlItem;
import org.sakaiproject.memory.api.Cache;
import org.sakaiproject.memory.api.CacheRefresher;
import org.sakaiproject.memory.api.MemoryService;
import org.sakaiproject.scorm.dao.api.ContentPackageDao;
import org.sakaiproject.scorm.model.api.SessionBean;
import org.sakaiproject.scorm.model.api.ContentPackage;
Expand Down Expand Up @@ -106,11 +103,6 @@ public void setPrevEntity(LessonEntity e) {
e.setNextEntity(this);
}

static MemoryService memoryService = null;
public void setMemoryService(MemoryService m) {
memoryService = m;
}

static MessageLocator messageLocator = null;
public void setMessageLocator(MessageLocator m) {
messageLocator = m;
Expand Down Expand Up @@ -295,30 +287,6 @@ public Date getDueDate() {
return null;
}

// the following methods all take references. So they're in effect static.
// They ignore the entity from which they're called.
// The reason for not making them a normal method is that many of the
// implementations seem to let you set access control and find submissions
// from a reference, without needing the actual object. So doing it this
// way could save some database activity

// access control
// no longer used, so there's no way to test them
public boolean addEntityControl(String siteId, final String groupId) throws IOException {
return false;

}

public boolean removeEntityControl(String siteId, String groupId) throws IOException {
return false;
}

// submission
// do we need the data from submission?
public boolean needSubmission(){
return true;
}

public Double toDouble(Object f) {
if (f instanceof Double)
return (Double)f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,27 +254,6 @@ public Date getDueDate() {
return null;
}

// access control
public boolean addEntityControl(String siteId, String groupId) throws IOException {

if (discussion == null && forumService != null)
discussion = forumService.getDiscussion(id, false);

return true;
}

public boolean removeEntityControl(String siteId, String groupId) throws IOException {

return true;
}

/**
* From LessonEntity
*/
public boolean needSubmission() {
return false;
}

/**
* From LessonEntity
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
init-method="init"
destroy-method="destroy">

<property name="memoryService"><ref bean="org.sakaiproject.memory.api.MemoryService"/></property>
<property name="messageLocator" ref="messageLocator"/>
<property name="gradebookService" ref="org.sakaiproject.service.gradebook.GradebookService"/>
<property name = "prevEntity" ref="org.sakaiproject.lessonbuildertool.service.Assignment2Entity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,171 +292,6 @@ public Date getOpenDate() {
return Date.from(assignment.getOpenDate());
}

// the following methods all take references. So they're in effect static.
// They ignore the entity from which they're called.
// The reason for not making them a normal method is that many of the
// implementations seem to let you set access control and find submissions
// from a reference, without needing the actual object. So doing it this
// way could save some database activity

// access control
public boolean addEntityControl(String siteId, String groupId) throws IOException {
Site site = null;
String ref = "/assignment/a/" + siteId + "/" + id;

try {
site = SiteService.getSite(siteId);
} catch (Exception e) {
log.warn("Unable to find site " + siteId, e);
return false;
}

Assignment edit = null;

try {
edit = assignmentService.getAssignment(ref);
} catch (IdUnusedException | PermissionException e) {
log.warn(e.getMessage(), e);
return false;
}

boolean doCancel = true;

try {
// need this to make sure we always unlock

if (edit.getTypeOfAccess() == Assignment.Access.GROUP) {
Collection<String> groups = edit.getGroups();
groupId = "/site/" + siteId + "/group/" + groupId;

if (groups.contains(groupId)) {
return true;
}

Group group = site.getGroup(groupId);
if (group == null) {
return false;
}

groups.add(group.getId());

edit.setIsGroup(true);

assignmentService.updateAssignment(edit);
doCancel = false;
return true;

} else {
// currently not grouped
Set<String> groups = new HashSet<>();
Group group = site.getGroup(groupId);

if (group == null) {
log.warn("Could not find Group");
return false;
}

groups.add(group.getId());

// this change mode to grouped
edit.setGroups(groups);
edit.setTypeOfAccess(Assignment.Access.GROUP);

assignmentService.updateAssignment(edit);
doCancel = false;
return true;
}
} catch (Exception e) {
log.warn(e.getMessage());
return false;
} finally {
if (doCancel) {
assignmentService.resetAssignment(edit);
}
}
}

public boolean removeEntityControl(String siteId, String groupId) throws IOException {
Site site = null;
String ref = "/assignment/a/" + siteId + "/" + id;
try {
site = SiteService.getSite(siteId);
} catch (Exception e) {
log.warn("Unable to find site " + siteId, e);
return false;
}

Assignment edit = null;

try {
edit = assignmentService.getAssignment(ref);
} catch (IdUnusedException | PermissionException e) {
log.warn(e.getMessage());
return false;
}

boolean doCancel = true;

try {
// need this to make sure we always unlock

if (edit.getTypeOfAccess() == Assignment.Access.GROUP) {
Collection<String> groups = edit.getGroups();
groupId = "/site/" + siteId + "/group/" + groupId;

if (!groups.contains(groupId)) {
// nothing to do
return true;
}

// odd; getgruops returns a list of string
// but setgroupacces wants a collection of actual groups
// so we have to copy the list
Set<String> newGroups = new HashSet<>();
for (String gid : groups) {
// remove our group
if (!gid.equals(groupId)) {
newGroups.add(gid);
}
}

if (newGroups.size() > 0) {
// there's groups left, just remove ours
edit.setGroups(newGroups);
} else {
// no groups left, put site access back
edit.setTypeOfAccess(Assignment.Access.SITE);
edit.setGroups(new HashSet<>());
}

assignmentService.updateAssignment(edit);
doCancel = false;
return true;

} else {
// currently not grouped
// nothing to do

return true;
}

} catch (Exception e) {
log.warn(e.getMessage());
return false;
} finally {
if (doCancel) {
assignmentService.resetAssignment(edit);
}
}

}

// submission
// do we need the data from submission?
public boolean needSubmission(){
return true;
}

public LessonSubmission getSubmission(String userId) {

if (assignment == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,29 +373,6 @@ public Date getDueDate() {
return null;
}

// the following methods all take references. So they're in effect static.
// They ignore the entity from which they're called.
// The reason for not making them a normal method is that many of the
// implementations seem to let you set access control and find submissions
// from a reference, without needing the actual object. So doing it this
// way could save some database activity

// access control
public boolean addEntityControl(String siteId, String groupId) throws IOException {
// not used for BLTI, control is done entirely within LB
return false;
}

public boolean removeEntityControl(String siteId, String groupId) throws IOException {
return false;
}

// submission
// do we need the data from submission?
public boolean needSubmission(){
return false;
}

public LessonSubmission getSubmission(String userId) {
// students don't have submissions to BLTI
return null;
Expand Down
Loading

0 comments on commit 3210cdf

Please sign in to comment.