Skip to content

Commit

Permalink
Merge pull request #2 from sakaicontrib/teamsconfig
Browse files Browse the repository at this point in the history
MS Teams configuration checks
  • Loading branch information
Miguel Pellicer authored May 13, 2022
2 parents e2c0e6a + 79d3138 commit 362517a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 5 deletions.
4 changes: 4 additions & 0 deletions teams/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<artifactId>sakai-component-manager</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public CompletableFuture<String> getAuthorizationTokenAsync(URL requestUrl) {
token.complete(result.accessToken());
} catch (Exception e) {
log.error("Exception retrieving token from Microsoft Graph Auth Provider: " + e.getClass(), e);
throw new IllegalArgumentException("Exception retrieving token from Microsoft Graph Auth Provider");
}
return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.meetings.teams.data.TeamsMeetingData;
Expand Down Expand Up @@ -67,6 +69,18 @@ public MicrosoftTeamsService() {
.buildClient();
}

/**
* Checking that MSTeams has been set up
* @return
*/
public boolean isMicrosofTeamsConfigured() {
String authority = serverConfigurationService.getString(MSTEAMS_PREFIX + AUTHORITY, null);
String clientId = serverConfigurationService.getString(MSTEAMS_PREFIX + CLIENT_ID, null);
String secret = serverConfigurationService.getString(MSTEAMS_PREFIX + SECRET, null);
String scope = serverConfigurationService.getString(MSTEAMS_PREFIX + SCOPE, null);
return StringUtils.isNoneBlank(authority, clientId, secret, scope);
}

/**
* Get Azure user list
* @return
Expand Down Expand Up @@ -140,7 +154,7 @@ public void createTeam(String name, String description, String microsoftLogin) t
* @param microsoftLogin
* @return
*/
public User getUserByMicrosoftLogin(String microsoftLogin) {
public User getUserByMicrosoftLogin(String microsoftLogin) throws Exception {
User result = graphClient.users(microsoftLogin).buildRequest().get();
return result;
}
Expand All @@ -154,7 +168,7 @@ public User getUserByMicrosoftLogin(String microsoftLogin) {
* @return
* @throws ParseException
*/
public TeamsMeetingData onlineMeeting(String presenter, String subject, Instant startDate, Instant endDate) throws ParseException {
public TeamsMeetingData onlineMeeting(String presenter, String subject, Instant startDate, Instant endDate) throws Exception {
// Get presenter user
User organizerUser = getUserByMicrosoftLogin(presenter);
// Organizer
Expand Down Expand Up @@ -193,8 +207,9 @@ public TeamsMeetingData onlineMeeting(String presenter, String subject, Instant
* Delete meeting
* @param organizerUser
* @param meetingId
* @throws Exception
*/
public void deleteMeeting(String organizerUser, String meetingId) {
public void deleteMeeting(String organizerUser, String meetingId) throws Exception {
User user = getUserByMicrosoftLogin(organizerUser);
graphClient.users(user.id).onlineMeetings(meetingId).buildRequest().delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public Meeting createMeeting(@RequestBody MeetingData data) throws MeetingsExcep
} catch (IdUnusedException e) {
log.error("Error retrieving site when sending notifications.", e);
throw new MeetingsException(e.getLocalizedMessage());
} catch (ParseException e) {
} catch (Exception e) {
log.error("Error creating meeting", e);
throw new MeetingsException(e.getLocalizedMessage());
}
Expand Down Expand Up @@ -606,6 +606,16 @@ public String getI18nProperties(@PathVariable String bundle, @PathVariable Strin
return i18n.toString();
}

/**
* Returns true if MS Teams is set up in Sakai properties
* @return
* @throws MeetingsException
*/
@GetMapping(value = "/meetings/teams/status", produces = MediaType.APPLICATION_JSON_VALUE)
public boolean isMicrosofTeamsConfigured() throws MeetingsException {
checkSakaiSession();
return teamsService.isMicrosofTeamsConfigured();
}

/**
* Method to send notifications to users about meetings, by level of priority
Expand Down
1 change: 1 addition & 0 deletions tool/src/main/resources/create-meeting.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cancel=Cancel
close_date=Close Date
error_create_meeting_500=There was a problem creating the meeting
error_create_meeting_unknown=Unknown error when trying to create meeting. Response code:
error_video_conferencing_config=The meetings tool requires at least one provider like Microsoft Teams or Zoom, please contact your service administrator or vendor.
group_participants=Participants from selected group(s)
info_no_groups=Group selection is disabled, because this Site has no groups.
meeting_description=Description
Expand Down
1 change: 1 addition & 0 deletions tool/src/main/resources/create-meeting_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cancel=Cancelar
close_date=Fecha de cierre
error_create_meeting_500=Hubo un problema al crear la reuni\u00F3n
error_create_meeting_unknown=Error desconocido al intentar crear la reuni\u00F3n. C\u00F3digo de respuesta:
error_video_conferencing_config=La herramienta necesita un proveedor como Microsoft Meetings o Zoom. Por favor contacta con el administrador o el proveedor del servicio.
group_participants=Participantes de los grupos seleccionados
info_no_groups=La selección de grupo está deshabilitada debido a que este sitio no tiene grupos.
meeting_description=Descripci\u00F3n
Expand Down
26 changes: 25 additions & 1 deletion ui/src/main/frontend/src/views/CreateMeeting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
:items="confServ"
:disabled="true"
v-model:value="formdata.confService"
@validation="setValidation('provider', $event)"
/>
</div>
</div>
Expand Down Expand Up @@ -233,7 +234,7 @@ export default {
value: "users",
},
],
validations: { title: false, dateOpen: true, dateClose: true },
validations: { title: false, provider: true, dateOpen: true, dateClose: true },
hadDateInput: false
};
},
Expand Down Expand Up @@ -385,6 +386,28 @@ export default {
})
.catch((error) => this.showError(error));
},
checkProviderConfigurations() {
fetch(
`${constants.toolPlacement}/meetings/teams/status`
)
.then((r) => {
if (r.ok) {
return r.json();
}
throw new Error(this.i18n.error_video_conferencing_config);
})
.then((data) => {
if (!data) {
console.log("mensaje recibido: ", data);
throw new Error(this.i18n.error_video_conferencing_config);
}
})
.catch((error) => {
this.formdata.confService = null;
this.validations.provider = false;
this.showError(error);
});
}
},
watch: {
"formdata.dateOpen"(newDate, oldDate) {
Expand Down Expand Up @@ -427,6 +450,7 @@ export default {
this.formdata.participantOption = this.participantOption;
this.formdata.groups = this.groupSelection;
this.loadGroups();
this.checkProviderConfigurations();
},
};
</script>

0 comments on commit 362517a

Please sign in to comment.