Search in sources :

Example 36 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method deletePodcastChannel.

@RequestMapping(value = "/rest/deletePodcastChannel", method = { RequestMethod.GET, RequestMethod.POST })
public void deletePodcastChannel(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isPodcastRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to administrate podcasts.");
        return;
    }
    int id = getRequiredIntParameter(request, "id");
    podcastService.deleteChannel(id);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 37 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method getShares.

@RequestMapping(value = "/rest/getShares", method = { RequestMethod.GET, RequestMethod.POST })
public void getShares(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    User user = securityService.getCurrentUser(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    Shares result = new Shares();
    for (Share share : shareService.getSharesForUser(user)) {
        org.libresonic.restapi.Share s = createJaxbShare(request, share);
        result.getShare().add(s);
        for (MediaFile mediaFile : shareService.getSharedFiles(share.getId(), musicFolders)) {
            s.getEntry().add(createJaxbChild(player, mediaFile, username));
        }
    }
    Response res = createResponse();
    res.setShares(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) User(org.libresonic.player.domain.User) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 38 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class ShareSettingsController method getShareInfos.

private List<ShareInfo> getShareInfos(HttpServletRequest request) {
    List<ShareInfo> result = new ArrayList<ShareInfo>();
    User user = securityService.getCurrentUser(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    for (Share share : shareService.getSharesForUser(user)) {
        List<MediaFile> files = shareService.getSharedFiles(share.getId(), musicFolders);
        if (!files.isEmpty()) {
            MediaFile file = files.get(0);
            result.add(new ShareInfo(shareService.getShareUrl(request, share), share, file.isDirectory() ? file : mediaFileService.getParentOf(file)));
        }
    }
    return result;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) User(org.libresonic.player.domain.User) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share)

Example 39 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method hls.

@RequestMapping(value = "/rest/hls", method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView hls(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isStreamRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to play files.");
        return null;
    }
    int id = getRequiredIntParameter(request, "id");
    MediaFile video = mediaFileDao.getMediaFile(id);
    if (video == null || video.isDirectory()) {
        error(request, response, ErrorCode.NOT_FOUND, "Video not found.");
        return null;
    }
    if (!securityService.isFolderAccessAllowed(video, user.getUsername())) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Access denied");
        return null;
    }
    hlsController.handleRequest(request, response);
    return null;
}
Also used : User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 40 with User

use of org.libresonic.player.domain.User in project libresonic by Libresonic.

the class RESTController method deleteShare.

@RequestMapping(value = "/rest/deleteShare", method = { RequestMethod.GET, RequestMethod.POST })
public void deleteShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    int id = getRequiredIntParameter(request, "id");
    Share share = shareService.getShareById(id);
    if (share == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Shared media not found.");
        return;
    }
    if (!user.isAdminRole() && !share.getUsername().equals(user.getUsername())) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Not authorized to delete shared media.");
        return;
    }
    shareService.deleteShare(id);
    writeEmptyResponse(request, response);
}
Also used : User(org.libresonic.player.domain.User) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

User (org.libresonic.player.domain.User)52 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)33 ModelAndView (org.springframework.web.servlet.ModelAndView)10 HashMap (java.util.HashMap)8 Test (org.junit.Test)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 Share (org.libresonic.player.domain.Share)6 UserSettings (org.libresonic.player.domain.UserSettings)6 MusicFolder (org.libresonic.player.domain.MusicFolder)5 Player (org.libresonic.player.domain.Player)4 UserSettingsCommand (org.libresonic.player.command.UserSettingsCommand)3 Playlist (org.libresonic.player.domain.Playlist)3 org.libresonic.restapi (org.libresonic.restapi)3 RedirectView (org.springframework.web.servlet.view.RedirectView)3 File (java.io.File)2 Date (java.util.Date)2 MediaFile (org.libresonic.player.domain.MediaFile)2 GrantedAuthority (org.springframework.security.core.GrantedAuthority)2 LinkedHashMap (java.util.LinkedHashMap)1 ReCaptcha (net.tanesha.recaptcha.ReCaptcha)1