-
-
Save zmokhtar/7143063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Page<ApiMemberSite> getSites(Member member, boolean includeSubscriptions, int pageNum, int pageSize) { | |
List permissions = [Permission.OWNER,Permission.ADMIN] | |
if(includeSubscriptions){ | |
permissions.add(Permission.MEMBER) | |
} | |
List<ApiMemberSite> sites = new ArrayList<ApiMemberSite>() | |
Page<Subscription> subscriptions = memberService.getSiteMemberships(member, permissions, pageNum, pageSize) | |
subscriptions.elements.each { | |
User user = userService.lookupUser(it.siteId) | |
//for every subscription site we process remove it from the set of userAttachedSites. | |
userAttachedSites.remove(user) | |
Site site = siteService.lookupSite(it.siteId) | |
if(user && site){ | |
sites << convertUserToApiSiteSimple(site, user, it.permission) | |
} | |
} | |
//for any remaining user sites that were not in the subscriptions list manually add it and fake a Permission of OWNER | |
Page<User> allAttachedSites = userService.getAttachedSites(member,pageNum,pageSize); | |
Set<User> userAttachedSites = allAttachedSites.elements as Set | |
userAttachedSites.each{ | |
Site site = siteService.lookupSite(it.userId) | |
if(site){ | |
sites << convertUserToApiSiteSimple(site,it,OWNER_PERMISSION) | |
} | |
} | |
new GenericPage<ApiMemberSite>(sites, subscriptions.pageNum, subscriptions.pageSize, subscriptions.totalSize) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment