Skip to content

Commit

Permalink
SAK-30464 Added unreadMessagesCount endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish committed Mar 8, 2016
1 parent 2ad6969 commit 9598e42
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions profile2/bundle/src/resources/profile.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Append /formatted to return a HTML formatted version of a user's profile styled
profile.action.academic=Retrieve the academic profile for a user. Includes full sized image and only academic related information. \
Append /formatted to return a HTML formatted version of a user's profile styled ready for use directly.

profile.action.unreadMessagesCount=Return the number of unread messages for a user. \
Returns a failure (404) if you do not have access to view the count of the user's messages.

profile.action.image=Retrieve the profile image for a user. \
Append /thumb to get the thumbnail (/profile/USER/image/thumb) if there is one. If there is no thumbnail, the main image will be returned. \
Append /avatar to get the avatar (/profile/USER/image/avatar) if there is one. If there is no avatar, the main image will be returned. \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.sakaiproject.profile2.logic.ProfileImageLogic;
import org.sakaiproject.profile2.logic.ProfileLinkLogic;
import org.sakaiproject.profile2.logic.ProfileLogic;
import org.sakaiproject.profile2.logic.ProfileMessagingLogic;
import org.sakaiproject.profile2.logic.SakaiProxy;
import org.sakaiproject.profile2.model.BasicConnection;
import org.sakaiproject.profile2.model.ProfileImage;
Expand Down Expand Up @@ -251,7 +252,26 @@ public Object getConnectionStatus(EntityReference ref, Map<String, Object> param

return connectionsLogic.getConnectionStatus(uuid, parameters.get("friendId").toString());
}


@EntityCustomAction(action="unreadMessagesCount",viewKey=EntityView.VIEW_SHOW)
public Object getUnreadMessagesCount(EntityReference ref) {

if (!sakaiProxy.isLoggedIn()) {
throw new SecurityException("You must be logged in to get the unread messages count.");
}

//convert input to uuid
String uuid = sakaiProxy.ensureUuid(ref.getId());
if (StringUtils.isBlank(uuid)) {
throw new EntityNotFoundException("Invalid user.", ref.getId());
}

if (sakaiProxy.isAdminUser() || sakaiProxy.getCurrentUserId().equals(uuid)) {
return new ActionReturn(messagingLogic.getAllUnreadMessagesCount(uuid));
} else {
throw new SecurityException("You can only view your own message count.");
}
}

@EntityCustomAction(action="formatted",viewKey=EntityView.VIEW_SHOW)
public Object getFormattedProfile(EntityReference ref) {
Expand Down Expand Up @@ -683,5 +703,8 @@ public String[] getHandledOutputFormats() {

@Setter
private ProfileLinkLogic linkLogic;

@Setter
private ProfileMessagingLogic messagingLogic;

}
1 change: 1 addition & 0 deletions profile2/tool/src/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<property name="imageLogic" ref="org.sakaiproject.profile2.logic.ProfileImageLogic" />
<property name="connectionsLogic" ref="org.sakaiproject.profile2.logic.ProfileConnectionsLogic" />
<property name="linkLogic" ref="org.sakaiproject.profile2.logic.ProfileLinkLogic" />
<property name="messagingLogic" ref="org.sakaiproject.profile2.logic.ProfileMessagingLogic" />
</bean>


Expand Down

0 comments on commit 9598e42

Please sign in to comment.