Search in sources :

Example 26 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class GettingStartedController method gettingStarted.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView gettingStarted(HttpServletRequest request) {
    if (request.getParameter("hide") != null) {
        settingsService.setGettingStartedEnabled(false);
        settingsService.save();
        return new ModelAndView(new RedirectView("home.view"));
    }
    Map<String, Object> map = new HashMap<>();
    ;
    map.put("runningAsRoot", "root".equals(System.getProperty("user.name")));
    return new ModelAndView("gettingStarted", "model", map);
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class MainController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(@RequestParam(name = "showAll", required = false) Boolean showAll, HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    Player player = playerService.getPlayer(request, response);
    List<MediaFile> mediaFiles = getMediaFiles(request);
    if (mediaFiles.isEmpty()) {
        return new ModelAndView(new RedirectView("notFound.view"));
    }
    MediaFile dir = mediaFiles.get(0);
    if (dir.isFile()) {
        dir = mediaFileService.getParentOf(dir);
    }
    // Redirect if root directory.
    if (mediaFileService.isRoot(dir)) {
        return new ModelAndView(new RedirectView("home.view?"));
    }
    String username = securityService.getCurrentUsername(request);
    if (!securityService.isFolderAccessAllowed(dir, username)) {
        return new ModelAndView(new RedirectView("accessDenied.view"));
    }
    UserSettings userSettings = settingsService.getUserSettings(username);
    List<MediaFile> children = mediaFiles.size() == 1 ? mediaFileService.getChildrenOf(dir, true, true, true) : getMultiFolderChildren(mediaFiles);
    List<MediaFile> files = new ArrayList<>();
    List<MediaFile> subDirs = new ArrayList<>();
    for (MediaFile child : children) {
        if (child.isFile()) {
            files.add(child);
        } else {
            subDirs.add(child);
        }
    }
    int userPaginationPreference = userSettings.getPaginationSize();
    if (userPaginationPreference <= 0) {
        showAll = true;
    }
    boolean thereIsMoreSubDirs = trimToSize(showAll, subDirs, userPaginationPreference);
    boolean thereIsMoreSAlbums = false;
    mediaFileService.populateStarredDate(dir, username);
    mediaFileService.populateStarredDate(children, username);
    map.put("dir", dir);
    map.put("files", files);
    map.put("subDirs", subDirs);
    map.put("ancestors", getAncestors(dir));
    map.put("coverArtSizeMedium", CoverArtScheme.MEDIUM.getSize());
    map.put("coverArtSizeLarge", CoverArtScheme.LARGE.getSize());
    map.put("player", player);
    map.put("user", securityService.getCurrentUser(request));
    map.put("visibility", userSettings.getMainVisibility());
    map.put("showAlbumYear", settingsService.isSortAlbumsByYear());
    map.put("showArtistInfo", userSettings.isShowArtistInfoEnabled());
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("brand", settingsService.getBrand());
    map.put("viewAsList", isViewAsList(request, userSettings));
    if (dir.isAlbum()) {
        List<MediaFile> sieblingAlbums = getSieblingAlbums(dir);
        thereIsMoreSAlbums = trimToSize(showAll, sieblingAlbums, userPaginationPreference);
        map.put("sieblingAlbums", sieblingAlbums);
        map.put("artist", guessArtist(children));
        map.put("album", guessAlbum(children));
    }
    try {
        MediaFile parent = mediaFileService.getParentOf(dir);
        map.put("parent", parent);
        map.put("navigateUpAllowed", !mediaFileService.isRoot(parent));
    } catch (SecurityException x) {
    // Happens if Podcast directory is outside music folder.
    }
    map.put("thereIsMore", (thereIsMoreSubDirs || thereIsMoreSAlbums) && !BooleanUtils.isTrue(showAll));
    Integer userRating = ratingService.getRatingForUser(username, dir);
    Double averageRating = ratingService.getAverageRating(dir);
    if (userRating == null) {
        userRating = 0;
    }
    if (averageRating == null) {
        averageRating = 0.0D;
    }
    map.put("userRating", 10 * userRating);
    map.put("averageRating", Math.round(10.0D * averageRating));
    map.put("starred", mediaFileService.getMediaFileStarredDate(dir.getId(), username) != null);
    String view;
    if (isVideoOnly(children)) {
        view = "videoMain";
    } else if (dir.isAlbum()) {
        view = "albumMain";
    } else {
        view = "artistMain";
    }
    return new ModelAndView(view, "model", map);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class PlaylistController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    User user = securityService.getCurrentUser(request);
    String username = user.getUsername();
    UserSettings userSettings = settingsService.getUserSettings(username);
    Player player = playerService.getPlayer(request, response);
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        return new ModelAndView(new RedirectView("notFound"));
    }
    map.put("playlist", playlist);
    map.put("user", user);
    map.put("player", player);
    map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username));
    map.put("partyMode", userSettings.isPartyModeEnabled());
    return new ModelAndView("playlist", "model", map);
}
Also used : Player(org.libresonic.player.domain.Player) Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) UserSettings(org.libresonic.player.domain.UserSettings) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class SettingsController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    User user = securityService.getCurrentUser(request);
    // Redirect to music folder settings if admin.
    String view = user.isAdminRole() ? "musicFolderSettings" : "personalSettings";
    return new ModelAndView(new RedirectView(view));
}
Also used : User(org.libresonic.player.domain.User) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class SetRatingController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    Integer rating = ServletRequestUtils.getIntParameter(request, "rating");
    if (rating == 0) {
        rating = null;
    }
    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    String username = securityService.getCurrentUsername(request);
    ratingService.setRatingForUser(username, mediaFile, rating);
    return new ModelAndView(new RedirectView("main.view?id=" + id));
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

RedirectView (org.springframework.web.servlet.view.RedirectView)79 ModelAndView (org.springframework.web.servlet.ModelAndView)68 Test (org.junit.Test)34 HashMap (java.util.HashMap)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 View (org.springframework.web.servlet.View)16 Authentication (org.springframework.security.core.Authentication)14 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)8 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)8 DefaultUserApprovalHandler (org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler)8 ServletException (javax.servlet.ServletException)7 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 TokenGranter (org.springframework.security.oauth2.provider.TokenGranter)7 Principal (org.apereo.cas.authentication.principal.Principal)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)6 CasProfile (org.pac4j.cas.profile.CasProfile)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6