Skip to content
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

Add Sakai theme information to LTI launch data #11330

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
import org.sakaiproject.tool.api.Session;
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.cover.UserDirectoryService;
import org.sakaiproject.util.api.FormattedText;
Expand Down Expand Up @@ -596,6 +598,8 @@ public static void addUserInfo(Properties ltiProps, Properties lti13subst, User
setProperty(lti13subst, LTICustomVars.USER_USERNAME, user.getEid());
setProperty(lti13subst, LTICustomVars.PERSON_SOURCEDID, user.getEid());

addThemeInfo(ltiProps, user.getId());

UserTimeService userTimeService = ComponentManager.get(UserTimeService.class);
TimeZone tz = userTimeService.getLocalTimeZone(user.getId());
if (tz != null) {
Expand Down Expand Up @@ -864,6 +868,26 @@ public static boolean sakaiInfo(Properties props, String context, String placeme
return true;
}

// Add the dark/light theme information from user preference and sakai properties
public static void addThemeInfo(Properties props, String userId) {
org.sakaiproject.user.api.PreferencesService preferencesService = ComponentManager.get(org.sakaiproject.user.api.PreferencesService.class);
org.sakaiproject.component.api.ServerConfigurationService serverConfigurationService = ComponentManager.get(org.sakaiproject.component.api.ServerConfigurationService.class);

// Add user preference for dark or light theme if set in preferences and themes are enabled for this instance of Sakai
boolean sakaiThemesEnabled = serverConfigurationService.getBoolean("portal.themes", true);
if ( sakaiThemesEnabled ) {
boolean usingDarkTheme = false;
Preferences prefs = preferencesService.getPreferences(userId);
if ( prefs != null ) {
usingDarkTheme = StringUtils.equals(prefs.getProperties(PreferencesService.USER_SELECTED_UI_THEME_PREFS).getProperty("theme"), "sakaiUserTheme-dark");
}
setProperty(props, LTICustomVars.THEME_DARK_MODE, String.valueOf(usingDarkTheme));
// Add theme base to launch if set in sakai properties
String themeBase = usingDarkTheme ? serverConfigurationService.getString(BasicLTIConstants.THEME_BASE_DARK_SAK_PROP, null) : serverConfigurationService.getString(BasicLTIConstants.THEME_BASE_LIGHT_SAK_PROP, null);
setProperty(props, LTICustomVars.THEME_BASE, themeBase);
}
}

public static void addPlacementInfo(Properties props, String placementId) {

// Get the placement to see if we are to release information
Expand Down Expand Up @@ -929,6 +953,8 @@ public static void addPlacementInfo(Properties props, String placementId) {
setProperty(props, "ext_sakai_eid", user.getEid());
}

addThemeInfo(props, user.getId());

String gradebookColumn = null;
// TODO: Figure this out
// It is a little tricky - the tool configuration on/off decides whether
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.tsugi.lti13.LTICustomVars;

@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down Expand Up @@ -54,13 +55,21 @@ public class SakaiExtension extends org.tsugi.jackson.objects.JacksonBase {
@JsonProperty("sakai_eid")
public String sakai_eid;

@JsonProperty("theme_base")
public String theme_base;

@JsonProperty("theme_dark_mode")
public String theme_dark_mode;

public void copyFromPost(Properties ltiProps) {
this.sakai_launch_presentation_css_url_list = ltiProps.getProperty("ext_sakai_launch_presentation_css_url_list");
this.sakai_academic_session = ltiProps.getProperty("ext_sakai_academic_session");
this.sakai_role = ltiProps.getProperty("ext_sakai_role");
this.sakai_server = ltiProps.getProperty("ext_sakai_server");
this.sakai_serverid = ltiProps.getProperty("ext_sakai_serverid");
this.sakai_eid = ltiProps.getProperty("ext_sakai_eid");
this.theme_base = ltiProps.getProperty(LTICustomVars.THEME_BASE);
this.theme_dark_mode = ltiProps.getProperty(LTICustomVars.THEME_DARK_MODE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,9 @@ public class BasicLTIConstants {
*/
public static final String TOOLCONSUMERINFO_VERSION = "ToolConsumerInfo.version";

/**
* Constants for theming and dark mode
*/
public static final String THEME_BASE_LIGHT_SAK_PROP = "basiclti.theme.base.light";
public static final String THEME_BASE_DARK_SAK_PROP = "basiclti.theme.base.dark";
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ public class LTICustomVars {
*/
public static final String PERSON_WEBADDRESS = "Person.webaddress";

/**
* Theme properties. Base color and dark mode enabled
*/
public static final String THEME_BASE = "theme_base";
public static final String THEME_DARK_MODE = "theme_dark_mode";

/**
* CONTEXT_ID
*
Expand Down Expand Up @@ -1101,6 +1107,8 @@ public class LTICustomVars {
PERSON_SMS,
PERSON_SOURCEDID,
PERSON_WEBADDRESS,
THEME_BASE,
THEME_DARK_MODE,
CONTEXT_ID, CONTEXT_ORG, CONTEXT_TYPE, CONTEXT_TYPE_DEFAULT,
CONTEXT_LABEL, CONTEXT_TITLE, CONTEXT_SOURCEDID,
CONTEXT_ID_HISTORY, CONTEXT_TIMEZONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5601,6 +5601,15 @@ rubrics.integration.token-secret=12345678900909091234
# lti.advantage.lti13servlet.public=MIIBIjANBgkqhkidjkssdhjk...
# lti.advantage.lti13servlet.private=MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYw...

# ###############################
# LAUNCH INFO FOR THEME
# ###############################

# Sets the base theme color for LTI tools
# default: null
# basiclti.theme.base.light=#171b48
# basiclti.theme.base.dark=#0E4466

# ###############################
# LTI Custom Substitution Values
# ###############################
Expand Down