Class SetupTeamSlackChannelsJob

java.lang.Object
edu.ucsb.cs156.frontiers.jobs.SetupTeamSlackChannelsJob
All Implemented Interfaces:
edu.ucsb.cs156.jobs.services.JobContextConsumer

public class SetupTeamSlackChannelsJob extends Object implements edu.ucsb.cs156.jobs.services.JobContextConsumer
Makes the public Slack channels of a course's teams match the teams.
  1. For each team, works out a channel name: "team-" followed by the team name in the form Slack requires (see sanitizeChannelName(String)). If two teams end up with the same channel name, the job stops with an error naming them, before touching Slack.
  2. Creates each channel, unless it already exists.
  3. Adds each member of each team, and the instructor of the course, to the team's channel, unless they are already in it. People are matched to Slack users by email; those without an active Slack account cannot be added, and are only counted.
  4. Removes from each channel every person who is neither a member of the team, nor the instructor, nor a member of the course staff. Bots (including the bot this job acts as) and members that are not users of the workspace are never removed.
A problem with one channel or one person is logged, and the job carries on with the rest. The last line of the log is a summary of how many channels were created or already existed, and how many members were added, already present, or removed.
  • Field Details

  • Constructor Details

    • SetupTeamSlackChannelsJob

      public SetupTeamSlackChannelsJob()
  • Method Details

    • getScopeType

      public String getScopeType()
      Specified by:
      getScopeType in interface edu.ucsb.cs156.jobs.services.JobContextConsumer
    • getScopeId

      public Long getScopeId()
      Specified by:
      getScopeId in interface edu.ucsb.cs156.jobs.services.JobContextConsumer
    • sanitizeChannelName

      public static String sanitizeChannelName(String teamName)
      Turns a team name into the form Slack requires of channel names: all lowercase, spaces replaced by hyphens, and every character other than letters, numbers, hyphens and underscores replaced by a hyphen.
      Parameters:
      teamName - the team name; may be null
      Returns:
      the sanitized name (without the "team-" prefix)
    • channelNameFor

      public static String channelNameFor(String teamName)
      Parameters:
      teamName - the team name
      Returns:
      the name of the team's Slack channel
    • accept

      public void accept(edu.ucsb.cs156.jobs.services.JobContext ctx) throws Exception
      Specified by:
      accept in interface edu.ucsb.cs156.jobs.services.JobContextConsumer
      Throws:
      Exception