Search in sources :

Example 1 with User

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

the class UserDaoTestCase method testUserSettings.

@Test
public void testUserSettings() {
    assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
    try {
        userDao.updateUserSettings(new UserSettings("sindre"));
        fail("Expected DataIntegrityViolationException.");
    } catch (DataIntegrityViolationException x) {
    }
    userDao.createUser(new User("sindre", "secret", null));
    assertNull("Error in getUserSettings.", userDao.getUserSettings("sindre"));
    userDao.updateUserSettings(new UserSettings("sindre"));
    UserSettings userSettings = userDao.getUserSettings("sindre");
    assertNotNull("Error in getUserSettings().", userSettings);
    assertNull("Error in getUserSettings().", userSettings.getLocale());
    assertNull("Error in getUserSettings().", userSettings.getThemeId());
    assertFalse("Error in getUserSettings().", userSettings.isFinalVersionNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isBetaVersionNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isSongNotificationEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isShowSideBar());
    assertFalse("Error in getUserSettings().", userSettings.isLastFmEnabled());
    assertNull("Error in getUserSettings().", userSettings.getLastFmUsername());
    assertNull("Error in getUserSettings().", userSettings.getLastFmPassword());
    assertSame("Error in getUserSettings().", TranscodeScheme.OFF, userSettings.getTranscodeScheme());
    assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
    assertEquals("Error in getUserSettings().", -1, userSettings.getSelectedMusicFolderId());
    assertFalse("Error in getUserSettings().", userSettings.isPartyModeEnabled());
    assertFalse("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
    assertSame("Error in getUserSettings().", AvatarScheme.NONE, userSettings.getAvatarScheme());
    assertNull("Error in getUserSettings().", userSettings.getSystemAvatarId());
    assertEquals("Error in getUserSettings().", 0, userSettings.getListReloadDelay());
    assertFalse("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
    assertEquals("Error in getUserSettings().", 0, userSettings.getPaginationSize());
    UserSettings settings = new UserSettings("sindre");
    settings.setLocale(Locale.SIMPLIFIED_CHINESE);
    settings.setThemeId("midnight");
    settings.setBetaVersionNotificationEnabled(true);
    settings.setSongNotificationEnabled(false);
    settings.setShowSideBar(true);
    settings.getMainVisibility().setBitRateVisible(true);
    settings.getPlaylistVisibility().setYearVisible(true);
    settings.setLastFmEnabled(true);
    settings.setLastFmUsername("last_user");
    settings.setLastFmPassword("last_pass");
    settings.setTranscodeScheme(TranscodeScheme.MAX_192);
    settings.setShowNowPlayingEnabled(false);
    settings.setSelectedMusicFolderId(3);
    settings.setPartyModeEnabled(true);
    settings.setNowPlayingAllowed(true);
    settings.setAvatarScheme(AvatarScheme.SYSTEM);
    settings.setSystemAvatarId(1);
    settings.setChanged(new Date(9412L));
    settings.setListReloadDelay(60);
    settings.setKeyboardShortcutsEnabled(true);
    settings.setPaginationSize(120);
    userDao.updateUserSettings(settings);
    userSettings = userDao.getUserSettings("sindre");
    assertNotNull("Error in getUserSettings().", userSettings);
    assertEquals("Error in getUserSettings().", Locale.SIMPLIFIED_CHINESE, userSettings.getLocale());
    assertEquals("Error in getUserSettings().", false, userSettings.isFinalVersionNotificationEnabled());
    assertEquals("Error in getUserSettings().", true, userSettings.isBetaVersionNotificationEnabled());
    assertEquals("Error in getUserSettings().", false, userSettings.isSongNotificationEnabled());
    assertEquals("Error in getUserSettings().", true, userSettings.isShowSideBar());
    assertEquals("Error in getUserSettings().", "midnight", userSettings.getThemeId());
    assertEquals("Error in getUserSettings().", true, userSettings.getMainVisibility().isBitRateVisible());
    assertEquals("Error in getUserSettings().", true, userSettings.getPlaylistVisibility().isYearVisible());
    assertEquals("Error in getUserSettings().", true, userSettings.isLastFmEnabled());
    assertEquals("Error in getUserSettings().", "last_user", userSettings.getLastFmUsername());
    assertEquals("Error in getUserSettings().", "last_pass", userSettings.getLastFmPassword());
    assertSame("Error in getUserSettings().", TranscodeScheme.MAX_192, userSettings.getTranscodeScheme());
    assertFalse("Error in getUserSettings().", userSettings.isShowNowPlayingEnabled());
    assertEquals("Error in getUserSettings().", 3, userSettings.getSelectedMusicFolderId());
    assertTrue("Error in getUserSettings().", userSettings.isPartyModeEnabled());
    assertTrue("Error in getUserSettings().", userSettings.isNowPlayingAllowed());
    assertSame("Error in getUserSettings().", AvatarScheme.SYSTEM, userSettings.getAvatarScheme());
    assertEquals("Error in getUserSettings().", 1, userSettings.getSystemAvatarId().intValue());
    assertEquals("Error in getUserSettings().", new Date(9412L), userSettings.getChanged());
    assertEquals("Error in getUserSettings().", 60, userSettings.getListReloadDelay());
    assertTrue("Error in getUserSettings().", userSettings.isKeyboardShortcutsEnabled());
    assertEquals("Error in getUserSettings().", 120, userSettings.getPaginationSize());
    userDao.deleteUser("sindre");
    assertNull("Error in cascading delete.", userDao.getUserSettings("sindre"));
}
Also used : User(org.libresonic.player.domain.User) UserSettings(org.libresonic.player.domain.UserSettings) Date(java.util.Date) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.Test)

Example 2 with User

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

the class UserDaoTestCase method testCreateUserTransactionalError.

@Test
public void testCreateUserTransactionalError() {
    User user = new User("muff1nman", "secret", "noemail") {

        @Override
        public boolean isPlaylistRole() {
            throw new RuntimeException();
        }
    };
    user.setAdminRole(true);
    int beforeSize = userDao.getAllUsers().size();
    boolean caughtException = false;
    try {
        userDao.createUser(user);
    } catch (RuntimeException e) {
        caughtException = true;
    }
    assertTrue("It was expected for createUser to throw an exception", caughtException);
    assertEquals(beforeSize, userDao.getAllUsers().size());
}
Also used : User(org.libresonic.player.domain.User) Test(org.junit.Test)

Example 3 with User

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

the class UserDaoTestCase method testGetUserByName.

@Test
public void testGetUserByName() {
    User user = new User("sindre", "secret", null);
    userDao.createUser(user);
    User newUser = userDao.getUserByName("sindre", true);
    assertNotNull("Error in getUserByName().", newUser);
    assertUserEquals(user, newUser);
    assertNull("Error in getUserByName().", userDao.getUserByName("sindre2", true));
    assertNull("Error in getUserByName().", userDao.getUserByName("sindre ", true));
    assertNull("Error in getUserByName().", userDao.getUserByName("bente", true));
    assertNull("Error in getUserByName().", userDao.getUserByName("", true));
    assertNull("Error in getUserByName().", userDao.getUserByName(null, true));
}
Also used : User(org.libresonic.player.domain.User) Test(org.junit.Test)

Example 4 with User

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

the class MoreController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<>();
    User user = securityService.getCurrentUser(request);
    String uploadDirectory = null;
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    if (musicFolders.size() > 0) {
        uploadDirectory = new File(musicFolders.get(0).getPath(), "Incoming").getPath();
    }
    StringBuilder jamstashUrl = new StringBuilder("http://jamstash.com/#/settings?u=" + StringUtil.urlEncode(user.getUsername()) + "&url=");
    jamstashUrl.append(StringUtil.urlEncode(NetworkService.getBaseUrl(request)));
    Player player = playerService.getPlayer(request, response);
    ModelAndView result = new ModelAndView();
    result.addObject("model", map);
    map.put("user", user);
    map.put("uploadDirectory", uploadDirectory);
    map.put("genres", mediaFileService.getGenres(false));
    map.put("currentYear", Calendar.getInstance().get(Calendar.YEAR));
    map.put("musicFolders", musicFolders);
    map.put("clientSidePlaylist", player.isExternalWithPlaylist() || player.isWeb());
    map.put("brand", settingsService.getBrand());
    map.put("jamstashUrl", jamstashUrl);
    return result;
}
Also used : Player(org.libresonic.player.domain.Player) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with User

use of org.libresonic.player.domain.User 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)

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