use of com.faforever.server.entity.GroupAssociation in project faf-java-server by FAForever.
the class FafUserDetailsTest method userWithGroup1IsAdmin.
@Test
public void userWithGroup1IsAdmin() throws Exception {
User user = (User) new User().setGroupAssociation(new GroupAssociation().setGroup(Group.ADMIN)).setPassword(TEST_PASSWORD).setLogin(TEST_USERNAME);
FafUserDetails fafUserDetails = new FafUserDetails(user);
assertThat(fafUserDetails.getAuthorities(), CoreMatchers.hasItems(new SimpleGrantedAuthority("ROLE_USER"), new SimpleGrantedAuthority("ROLE_ADMIN")));
}
use of com.faforever.server.entity.GroupAssociation in project faf-java-server by FAForever.
the class ChatService method onPlayerOnlineEvent.
@EventListener
public void onPlayerOnlineEvent(PlayerOnlineEvent event) {
Chat chat = properties.getChat();
Set<String> channels = new HashSet<>(3, 1);
channels.addAll(chat.getDefaultChannels());
Optional.ofNullable(event.getPlayer().getClan()).map(clan -> (String.format(chat.getClanChannelFormat(), clan.getTag()))).ifPresent(channels::add);
User user = event.getPlayer().getUser();
GroupAssociation groupAssociation = user.getGroupAssociation();
if (groupAssociation != null) {
switch(groupAssociation.getGroup()) {
case ADMIN:
channels.addAll(chat.getAdminChannels());
break;
case MODERATOR:
channels.addAll(chat.getModeratorChannels());
break;
default:
throw new ProgrammingError("Uncovered group: " + groupAssociation.getGroup());
}
}
clientService.sendChatChannels(channels, event.getPlayer());
}
use of com.faforever.server.entity.GroupAssociation in project faf-java-server by FAForever.
the class FafUserDetailsTest method userWithoutGroup1IsNotAdmin.
@Test
public void userWithoutGroup1IsNotAdmin() throws Exception {
User user = (User) new User().setGroupAssociation(new GroupAssociation().setGroup(Group.MODERATOR)).setPassword(TEST_PASSWORD).setLogin(TEST_USERNAME);
FafUserDetails fafUserDetails = new FafUserDetails(user);
assertThat(fafUserDetails.getAuthorities(), hasSize(1));
assertThat(fafUserDetails.getAuthorities().iterator().next().getAuthority(), is("ROLE_USER"));
}
use of com.faforever.server.entity.GroupAssociation in project faf-java-server by FAForever.
the class ChatServiceTest method testJoinChannels.
@SuppressWarnings("unchecked")
private void testJoinChannels(Group group, String... expectedChannels) {
User user = (User) new User().setPassword("pw").setGroupAssociation(group == null ? null : new GroupAssociation().setGroup(group)).setLogin("junit");
Player player = new Player().setUser(user).setClanMemberships(Collections.singletonList(new ClanMembership().setClan(new Clan().setTag("junit"))));
instance.onPlayerOnlineEvent(new PlayerOnlineEvent(this, player));
ArgumentCaptor<Set<String>> captor = ArgumentCaptor.forClass((Class) Set.class);
verify(clientService).sendChatChannels(captor.capture(), any());
Set<String> channels = captor.getValue();
assertThat(channels, containsInAnyOrder(expectedChannels));
}
Aggregations