Skip to content

Commit

Permalink
More code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuoY121 committed Sep 4, 2024
1 parent 6770b6c commit cc65693
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 107 deletions.
2 changes: 1 addition & 1 deletion basiclti/basiclti-tool/src/bundle/ltitool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tool.import.title=Do you want to change the title of this tool to:
tool.import.description=Do you want to change the description of this tool to:
tool.import.success=Imported dynamic registration data into the form, please review and save.
tool.import.error=Error retrieving LTI 1.3 configuration from URL.
tool.new.insert.start.header=Install LTI 1.x Tool
tool.new.insert.start.header=Install LTI Tool
tool.new.insert.start.text.admin=This screen starts the process of inserting a new LTI tool. A draft version of the tool will be created from this page, and you will be allowed to continue to add the necessary data to complete the tool installation on the following screen. Once this screen is completed, you will be allowed to use LTI Dynamic Registration on the following screen.
tool.new.insert.start.text.instructor=This can be used to install an LTI 1.1 tool but not an LTI 1.3 tool. Only system administrators can install LTI 1.3 tools.
tool.new.insert.start.title=Tool Title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,8 @@ public String buildToolDeletePanelContext(VelocityPortlet portlet, Context conte
List<Map<String, Object>> toolSites = ltiService.getToolSitesByToolId(id, getSiteId(state));
context.put("tool_site_count", toolSites.size());

context.put("isAdmin", ltiService.isAdmin(getSiteId(state)));

state.removeAttribute(STATE_SUCCESS);
return "lti_tool_delete";
}
Expand Down Expand Up @@ -1395,9 +1397,6 @@ public String buildToolInsertPanelContext(VelocityPortlet portlet, Context conte

context.put("tlang", rb);

// TODO: When do we need "includeLatestJQuery"?
// context.put("includeLatestJQuery", PortalUtils.includeLatestJQuery("LTIAdminTool"));

if (!ltiService.isMaintain(getSiteId(state))) {
addAlert(state, rb.getString("error.maintain.edit"));
return "lti_error";
Expand Down Expand Up @@ -1473,7 +1472,6 @@ public void doToolInsert(RunData data, Context context) {
}

long key = Long.parseLong(retval.toString());
// switchPanel(state, "ToolEdit&autoStart=true&id=" + key); // NOTE: I am not sure where we need "autoStart"
switchPanel(state, "ToolEdit&id=" + key);
}

Expand Down Expand Up @@ -1532,12 +1530,12 @@ public String buildToolEditPanelContext(VelocityPortlet portlet, Context context
+ "&tool_id=" + tool.get(LTIService.LTI_ID);
context.put("deployUrl", deployUrl);

context.put("doToolAction", BUTTON + "doToolUpdate");
context.put("doToolAction", BUTTON + "doToolEdit");

return "lti_tool_update";
return "lti_tool_edit";
}

public void doToolUpdate(RunData data, Context context) {
public void doToolEdit(RunData data, Context context) {

String peid = ((JetspeedRunData) data).getJs_peid();
SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);
Expand Down Expand Up @@ -1597,95 +1595,6 @@ public void doToolUpdate(RunData data, Context context) {
}
}


// Insert or edit
public void doToolPut(RunData data, Context context) {
String peid = ((JetspeedRunData) data).getJs_peid();
SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);

if (!ltiService.isMaintain(getSiteId(state))) {
addAlert(state, rb.getString("error.maintain.delete"));
switchPanel(state, "Error");
return;
}
Properties reqProps = data.getParameters().getProperties();

String newSecret = reqProps.getProperty(LTIService.LTI_SECRET);
if (LTIService.SECRET_HIDDEN.equals(newSecret)) {
reqProps.remove(LTIService.LTI_SECRET);
newSecret = null;
}

if (newSecret != null) {
newSecret = SakaiBLTIUtil.encryptSecret(newSecret.trim());
reqProps.setProperty(LTIService.LTI_SECRET, newSecret);
}

// Retrieve the old tool
String id = data.getParameters().getString(LTIService.LTI_ID);

Long key = null;
if (id != null) {
try {
key = new Long(id);
} catch (NumberFormatException e) {
addAlert(state, rb.getString("error.tool.not.found"));
switchPanel(state, "Error");
return;
}
}

Map<String, Object> tool = null;
if (key != null) {
tool = ltiService.getTool(key, getSiteId(state));
if (tool == null) {
addAlert(state, rb.getString("error.tool.not.found"));
switchPanel(state, "Error");
return;
}
}

// Handle the incoming LTI 1.3 data
String form_lti13 = reqProps.getProperty("lti13");
String form_lti13_client_id = StringUtils.trimToNull(reqProps.getProperty(LTIService.LTI13_CLIENT_ID));

String old_lti13_client_id = null;

boolean displayPostInsert = false;
if ("1".equals(form_lti13)) {
KeyPair kp = null;
if (old_lti13_client_id == null && form_lti13_client_id == null) {
reqProps.setProperty(LTIService.LTI13_CLIENT_ID, UUID.randomUUID().toString());
displayPostInsert = true;
}
}

String success = null;
Object retval = null;
if (key == null) {
retval = ltiService.insertTool(reqProps, getSiteId(state));
success = rb.getString("success.created");
} else {
retval = ltiService.updateTool(key, reqProps, getSiteId(state));
success = rb.getString("success.updated");
}

if (retval instanceof String) {
state.setAttribute(STATE_POST, reqProps);
addAlert(state, (String) retval);
state.setAttribute(STATE_ID, id);
return;
}

state.setAttribute(STATE_SUCCESS, success);
if ( displayPostInsert ) {
if ( key == null ) key = new Long(retval.toString());
switchPanel(state, "ToolPostInsert&id="+key);
} else {
switchPanel(state, "ToolSystem");
}
}

/**
* Content related methods ------------------------------
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="portletBody">
<script type="text/javascript" src="/library/js/headscripts.js"></script>
<script>
includeLatestJQuery('lti_tool_update.vm');
includeLatestJQuery('lti_tool_edit.vm');
includeWebjarLibrary('fontawesome-iconpicker');
</script>
<h3>$tlang.getString("tool.put")</h3>
Expand Down
1 change: 0 additions & 1 deletion basiclti/basiclti-tool/src/webapp/vm/lti_tool_insert.vm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<p>$tlang.getString("tool.new.insert.start.text.instructor")</p>
#end


#if ($alertMessage)<div class="sak-banner-error">$tlang.getString("gen.alert") $formattedText.escapeHtml($alertMessage)</div>#end

<form action="#toolForm("")" method="post" name="customizeForm" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ${includeLatestJQuery}

#if ($isAdmin)
<div align="right" style="padding:10px">
<a href="" title="$tlang.getString("add.tool.site")" onclick="location = '$sakai_ActionURL.setPanel("ToolSiteInsert")&tool_id=$toolId';return false;"> $tlang.getString("add.tool.site")</a>
<a href="" class="btn btn-primary" title="$tlang.getString("add.tool.site")" onclick="location = '$sakai_ActionURL.setPanel("ToolSiteInsert")&tool_id=$toolId';return false;"> $tlang.getString("add.tool.site")</a>
</div>
#end

Expand Down
8 changes: 1 addition & 7 deletions basiclti/basiclti-tool/src/webapp/vm/lti_tool_system.vm
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,7 @@ ${includeLatestJQuery}
#if ($configMessage)<div class="sak-banner-error">$tlang.getString("gen.alert") $formattedText.escapeHtml($configMessage)</div>#end
#if ($isAdmin || $allowMaintainerAddSystemTool)
<div align="right" style="padding:10px">
<a href="" title="$tlang.getString("add.to.system.insert.new")" onclick="location = '$sakai_ActionURL.setPanel("ToolInsert")';return false;"> $tlang.getString("add.to.system.insert.new")</a>
## <br/>
## <a href="" title="$tlang.getString("add.to.system")" onclick="location = '$sakai_ActionURL.setPanel("ToolInsert")';return false;"> $tlang.getString("add.to.system")</a>
## #if ($isAdmin )
## <br/><a href="" title="$tlang.getString("add.auto")" onclick="location = '$sakai_ActionURL.setPanel("AutoInsert")';return false;"> $tlang.getString("add.auto")</a>
## #end
<a href="" class="btn btn-primary" title="$tlang.getString("add.to.system.insert.new")" onclick="location = '$sakai_ActionURL.setPanel("ToolInsert")';return false;"> $tlang.getString("add.to.system.insert.new")</a>
</div>
#end
<br/>
Expand Down Expand Up @@ -180,7 +175,6 @@ ${includeLatestJQuery}
<ul style="list-style: none;">
<li style="display:inline"><a href="$sakai_ActionURL.setPanel("ToolEdit")&id=$tool.get("id")">$tlang.getString("gen.edit")</a></li>
<li style="display:inline"><span aria-hidden="true"> / </span> <a href="$sakai_ActionURL.setPanel("ToolDelete")&id=$tool.get("id")">$tlang.getString("gen.delete")</a> </li>

#if ( $tool.get("lti_content_count") > 0 )
<li style="display:inline"><span aria-hidden="true"> / </span> <a href="$sakai_ActionURL.setPanel("ToolTransfer")&id=$tool.get("id")">$tlang.getString("gen.transfer")</a></li>
#end
Expand Down

0 comments on commit cc65693

Please sign in to comment.