Skip to content

Commit

Permalink
SAK-41905 - site info: Import from Site always shows complete list of…
Browse files Browse the repository at this point in the history
… sites, including hidden ones. (#8088)
  • Loading branch information
Miguel Pellicer committed Apr 1, 2020
1 parent e30bda3 commit 3203e72
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public interface PreferencesService extends EntityProducer

/** Prefs key under which stuff like the editor typepreferences stored. */
static final String EDITOR_PREFS_TYPE = "editor:type";


/** Prefs key under which stuff like the editor typepreferences stored. */
public static final String SITENAV_PREFS_EXCLUDE_KEY = "exclude";

/**
* Access a set of preferences associated with this id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,13 @@ sitesetupquestion.alert=Please answer the required question(s).
sitinfimp.selection=Please choose a method below to proceed:
sitinfimp.migrate=I would like to replace my data
sitinfimp.migrate.info=Any existing data will be overwritten, replaced by your import data.
sitinfimp.hiddensites = Import from Hidden Sites
sitinfimp.hiddensites.info = The following sites are hidden by preferences. You can still import materials from those sites.
sitinfimp.import=I would like to merge my data
sitinfimp.import.info=Your imported data will merge with existing data.
sitinfimp.import.user=I would like to merge my user(s)
sitinfimp.import.user.info=Your imported user(s) will merge with existing users. This method does not import roster-provided users.
sitinfimp.mysites = Import from My Sites
sitinfimp.replace=You can replace material in one of your sites by importing material from another site that you own. Any existing data will be overwritten, replaced by your import data.
sitinfimp.choose = Choose the material you want to re-use from this site.
sitinfimp.wikinote=(Existing content will be archived and can be accessed from the History link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
import org.sakaiproject.tool.api.ToolSession;
import org.sakaiproject.tool.cover.SessionManager;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.user.api.Preferences;
import org.sakaiproject.user.api.PreferencesService;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserNotDefinedException;
Expand Down Expand Up @@ -4205,11 +4206,31 @@ private Set<CourseSet> filterCourseSetList(Set<CourseSet> courseSets) {
*/
private void putImportSitesInfoIntoContext(Context context, Site site, SessionState state, boolean ownTypeOnly) {
context.put("currentSite", site);
context.put("importSiteList", state
.getAttribute(STATE_IMPORT_SITES));
context.put("sites", SiteService.getSites(
org.sakaiproject.site.api.SiteService.SelectionType.UPDATE,
ownTypeOnly?site.getType():null, null, null, SortType.TITLE_ASC, null));
context.put("importSiteList", state.getAttribute(STATE_IMPORT_SITES));
final List<Site> siteList = SiteService.getSites(org.sakaiproject.site.api.SiteService.SelectionType.UPDATE, ownTypeOnly?site.getType():null, null, null, SortType.TITLE_ASC, null);
List<String> hiddenSiteIdList = new ArrayList<>();
List<Site> hiddenSiteList = new ArrayList<>();
List<Site> visibleSiteList = new ArrayList<>();
Preferences preferences = preferencesService.getPreferences(userDirectoryService.getCurrentUser().getId());
if (preferences != null) {
ResourceProperties properties = preferences.getProperties(PreferencesService.SITENAV_PREFS_KEY);
hiddenSiteIdList = (List<String>) properties.getPropertyList(PreferencesService.SITENAV_PREFS_EXCLUDE_KEY);
}

if (hiddenSiteIdList != null && !hiddenSiteIdList.isEmpty()) {
for (Site s : siteList) {
if (hiddenSiteIdList.contains(s.getId())) {
hiddenSiteList.add(s);
} else {
visibleSiteList.add(s);
}
}
} else {
visibleSiteList.addAll(siteList);
}

context.put("sites", visibleSiteList);
context.put("hiddenSites", hiddenSiteList);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,63 @@
<form name="featuresForm" action="#toolForm("$action")" method="post">
## import is possible when use has maintain rights on at least one site other than the current one
#if ($!sites && $sites.size()>1)
<p class="step">
$tlang.getString("sitinfimp.reuse")
</p>
<p class="instruction">
$tlang.getString("sitinfimp.replace")
</p>
#set ($siteIDCounter =0)
#foreach($site in $sites)
#set ($siteIDCounter = $siteIDCounter + 1)
#if ($!currentSite && ($site.Id != $!currentSite.Id))
<div class="radio">
<label for="site_$siteIDCounter">
<input type="radio" name="importSites" id="site_$siteIDCounter" value="$site.getId()"
#if ($!importSiteList.containsKey($!site))
checked="checked"
<div class="panel-group" id="sitesAccordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#sitesAccordion" href="#mysites">$tlang.getString("sitinfimp.mysites") ($sites.size())</a>
</h4>
</div>
<div id="mysites" class="panel-collapse collapse in">
<div class="panel-body">
#set ($siteIDCounter =0)
#foreach($site in $sites)
#set ($siteIDCounter = $siteIDCounter + 1)
#if ($!currentSite && ($site.Id != $!currentSite.Id))
<div class="radio">
<label for="site_$siteIDCounter">
<input type="radio" name="importSites" id="site_$siteIDCounter" #if ($!importSiteList.containsKey($!site)) checked="checked"#end value="$site.getId()"/>
$formattedText.escapeHtml($site.getTitle())
</label>
</div>
#end
#end
</div>
</div>
</div>

#if ($!hiddenSites && $hiddenSites.size() > 0)
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#sitesAccordion" href="#hiddenSites">$tlang.getString("sitinfimp.hiddensites") ($hiddenSites.size())</a>
</h4>
</div>
<div id="hiddenSites" class="panel-collapse collapse">
<div class="panel-body">
<p class="instruction">
tlang.getString("sitinfimp.hiddensites.info")
</p>
#foreach($hiddenSite in $hiddenSites)
#set ($siteIDCounter = $siteIDCounter + 1)
#if ($!currentSite && ($hiddenSite.Id != $!currentSite.Id))
<div class="radio">
<label for="site_$siteIDCounter">
<input type="radio" name="importSites" id="site_$siteIDCounter" #if ($!importSiteList.containsKey($!hiddenSite)) checked="checked" #end value="$hiddenSite.getId()"/>
$formattedText.escapeHtml($hiddenSite.getTitle())
</label>
</div>
#end
/>
$formattedText.escapeHtml($site.getTitle())
</label>
</div>
#end
#end
</div>
</div>
</div>
#end
</div>

<input type="hidden" name="back" value="58" />
<input type="hidden" name="templateIndex" value="59" />
<input type="hidden" name="continue" value="60" />
Expand Down

0 comments on commit 3203e72

Please sign in to comment.