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

ENG-5426: Gravatar integration #254

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions cms-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ entando-plugin-jacms

CMS is a plugin that allows to registered users to manage in the Back Office dynamic contents and digital assets.

**Installation**

In order to install the CMS plugin, you must insert the following dependency in the pom.xml file of your project:

```
<dependency>
<groupId>org.entando.entando.bundles.app-view</groupId>
<artifactId>entando-app-view-cms-default</artifactId>
<version>${entando.version}</version>
<type>war</type>
</dependency>
```

# Developing against local versions of upstream projects (e.g. admin-console, entando-engine).

Full instructions on how to develop against local versions of upstream projects are available in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,6 @@ private SystemConstants(){}

public static final String USER_PROFILE_ATTRIBUTE_DISABLING_CODE_ON_EDIT = "userprofile:onEdit";

/**
* The name of the role for attribute attribute that contains the profile picture file name
*/
public static final String USER_PROFILE_ATTRIBUTE_ROLE_PROFILE_PICTURE = "userprofile:profilepicture";

public static final String ENTANDO_THREAD_NAME_PREFIX = "EntandoThread_";

public static final String API_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ public interface IUserPreferencesDAO {
* @throws EntException the ent exception
*/
void deleteUserPreferences(String username) throws EntException;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
* Copyright 2023-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
Expand Down Expand Up @@ -54,4 +54,18 @@ public interface IUserPreferencesManager {
* @throws EntException the ent exception
*/
void deleteUserPreferences(String username) throws EntException;
}

boolean isUserGravatarEnabled(String username) throws EntException;

void updateUserGravatarPreference(String username, boolean enabled) throws EntException;

public default UserPreferences createDefaultUserPreferences(String username) {
UserPreferences userPreferences = new UserPreferences();
userPreferences.setUsername(username);
userPreferences.setWizard(true);
userPreferences.setTranslationWarning(true);
userPreferences.setLoadOnPageSelect(true);
return userPreferences;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@XmlRootElement(name = "userPreferences")
@XmlType(propOrder = {"username", "wizard", "loadOnPageSelect", "translationWarning", "defaultPageOwnerGroup",
"defaultPageJoinGroups", "defaultContentOwnerGroup", "defaultContentJoinGroups", "defaultWidgetOwnerGroup",
"defaultWidgetJoinGroups", "disableContentMenu"})
"defaultWidgetJoinGroups", "disableContentMenu", "gravatar"})
public class UserPreferences implements Serializable {

private String username;
Expand All @@ -35,6 +35,7 @@ public class UserPreferences implements Serializable {
private String defaultWidgetOwnerGroup;
private String defaultWidgetJoinGroups;
private boolean disableContentMenu;
private boolean gravatar;

@XmlElement(name = "username", required = true)
public String getUsername() {
Expand Down Expand Up @@ -135,6 +136,15 @@ public void setDisableContentMenu(boolean disableContentMenu) {
this.disableContentMenu = disableContentMenu;
}

@XmlElement(name = "gravatar")
public boolean isGravatar() {
return gravatar;
}

public void setGravatar(boolean gravatar) {
this.gravatar = gravatar;
}

@Override
public String toString() {
return "UserPreferences{" +
Expand All @@ -148,7 +158,8 @@ public String toString() {
", defaultContentJoinGroups='" + defaultContentJoinGroups + '\'' +
", defaultWidgetOwnerGroup='" + defaultWidgetOwnerGroup + '\'' +
", defaultWidgetJoinGroups='" + defaultWidgetJoinGroups + '\'' +
", disableContentMenu='" + disableContentMenu +
", disableContentMenu='" + disableContentMenu + '\'' +
", gravatar='" + gravatar +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public class UserPreferencesDAO extends AbstractDAO implements IUserPreferencesD
private static final String LOAD_USER_PREFERENCES =
"SELECT wizard, loadonpageselect, translationwarning, defaultpageownergroup, defaultpagejoingroups, "
+ "defaultcontentownergroup, defaultcontentjoingroups, defaultwidgetownergroup, "
+ "defaultwidgetjoingroups, disableContentMenu FROM userpreferences WHERE username = ? ";
+ "defaultwidgetjoingroups, disableContentMenu, gravatar FROM userpreferences WHERE username = ? ";

private static final String ADD_USER_PREFERENCES =
"INSERT INTO userpreferences (username, wizard, loadonpageselect, translationwarning, "
+ "defaultpageownergroup, defaultpagejoingroups, defaultcontentownergroup, "
+ "defaultcontentjoingroups, defaultwidgetownergroup, defaultwidgetjoingroups, disableContentMenu) "
+ "VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
+ "defaultcontentjoingroups, defaultwidgetownergroup, defaultwidgetjoingroups, disableContentMenu, gravatar) "
+ "VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";

private static final String UPDATE_USER_PREFERENCES =
"UPDATE userpreferences SET wizard = ? , loadonpageselect = ? , translationwarning = ? , "
+ "defaultpageownergroup = ? , defaultpagejoingroups = ? , defaultcontentownergroup = ? , "
+ "defaultcontentjoingroups = ? , defaultwidgetownergroup = ?, defaultwidgetjoingroups = ? , "
+ "disableContentMenu = ? WHERE username = ? ";
+ "disableContentMenu = ? , gravatar = ? WHERE username = ? ";

private static final String DELETE_USER_PREFERENCES =
"DELETE FROM userpreferences WHERE username = ? ";
Expand Down Expand Up @@ -70,6 +70,7 @@ public UserPreferences loadUserPreferences(String username) throws EntException
response.setDefaultWidgetOwnerGroup(res.getString(8));
response.setDefaultWidgetJoinGroups(res.getString(9));
response.setDisableContentMenu(1 == res.getInt(10));
response.setGravatar(1 == res.getInt(11));
}
} catch (SQLException e) {
_logger.error("Error loading user preferences for user {}", username, e);
Expand Down Expand Up @@ -99,6 +100,7 @@ public void addUserPreferences(UserPreferences userPreferences) throws EntExcept
stat.setString(9, userPreferences.getDefaultWidgetOwnerGroup());
stat.setString(10, userPreferences.getDefaultWidgetJoinGroups());
stat.setInt(11, userPreferences.getDisableContentMenu() ? 1 : 0);
stat.setInt(12, userPreferences.isGravatar() ? 1 : 0);
stat.executeUpdate();
conn.commit();
} catch (SQLException e) {
Expand Down Expand Up @@ -128,7 +130,8 @@ public void updateUserPreferences(UserPreferences userPreferences) throws EntExc
stat.setString(8, userPreferences.getDefaultWidgetOwnerGroup());
stat.setString(9, userPreferences.getDefaultWidgetJoinGroups());
stat.setInt(10, userPreferences.getDisableContentMenu() ? 1 : 0);
stat.setString(11, userPreferences.getUsername());
stat.setInt(11, userPreferences.isGravatar() ? 1 : 0);
stat.setString(12, userPreferences.getUsername());
stat.executeUpdate();
conn.commit();
} catch (SQLException e) {
Expand Down Expand Up @@ -158,4 +161,5 @@ public void deleteUserPreferences(String username) throws EntException {
closeDaoResources(null, stat, conn);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
* Copyright 2023-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
Expand All @@ -13,6 +13,7 @@
*/
package org.entando.entando.aps.system.services.userpreferences;

import java.util.Optional;
import org.entando.entando.ent.exception.EntException;

public class UserPreferencesManager implements IUserPreferencesManager {
Expand All @@ -34,6 +35,24 @@ public void updateUserPreferences(UserPreferences userPreferences) throws EntExc
userPreferencesDAO.updateUserPreferences(userPreferences);
}

@Override
public boolean isUserGravatarEnabled(String username) throws EntException {
return Optional.ofNullable(this.getUserPreferences(username)).map(p -> p.isGravatar()).orElse(Boolean.FALSE);
}

@Override
public void updateUserGravatarPreference(String username, boolean enabled) throws EntException {
UserPreferences userPreferences = this.getUserPreferences(username);
if (null != userPreferences) {
userPreferences.setGravatar(enabled);
this.updateUserPreferences(userPreferences);
} else {
userPreferences = this.createDefaultUserPreferences(username);
userPreferences.setGravatar(enabled);
this.addUserPreferences(userPreferences);
}
}

@Override
public void deleteUserPreferences(String username) throws EntException {
userPreferencesDAO.deleteUserPreferences(username);
Expand All @@ -42,4 +61,5 @@ public void deleteUserPreferences(String username) throws EntException {
public void setUserPreferencesDAO(UserPreferencesDAO userPreferencesDAO) {
this.userPreferencesDAO = userPreferencesDAO;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public UserPreferencesDto updateUserPreferences(String username, UserPreferences
if (request.getDisableContentMenu() != null) {
userPreferences.setDisableContentMenu(request.getDisableContentMenu());
}
if (request.getGravatar() != null) {
userPreferences.setGravatar(request.getGravatar());
}
userPreferencesManager.updateUserPreferences(userPreferences);
return new UserPreferencesDto(userPreferencesManager.getUserPreferences(username));
} else {
Expand All @@ -109,12 +112,8 @@ public UserPreferencesDto updateUserPreferences(String username, UserPreferences

private void createNewDefaultUserPreferences(String username) {
try {
UserPreferences userPreferences = new UserPreferences();
userPreferences.setUsername(username);
userPreferences.setWizard(true);
userPreferences.setTranslationWarning(true);
userPreferences.setLoadOnPageSelect(true);
userPreferencesManager.addUserPreferences(userPreferences);
UserPreferences userPreferences = this.userPreferencesManager.createDefaultUserPreferences(username);
this.userPreferencesManager.addUserPreferences(userPreferences);
} catch (EntException e) {
logger.error("Error in creating new default userPreferences for {}", username, e);
throw new RestServerError("Error creating new default userPreferences", e);
Expand Down
Loading
Loading