Class SetupPrivateSlackChannelsJob

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

public class SetupPrivateSlackChannelsJob extends Object implements edu.ucsb.cs156.jobs.services.JobContextConsumer
Gives each student of a course a private Slack channel shared with the staff of the course.
  1. For each roster student (status ROSTER or MANUAL) with an active Slack account, works out a channel name: "private-first-last" (see channelNameFor(String, String, String)). The first and last name come from the student's Slack profile when it has them, and otherwise from the roster; only the first word of the first name is used. Students who would get the same name also get the part of their email before the @ at the end.
  2. Finds the channel each student already has. A channel is a student's if it is a private channel that this bot created, and that student is the only one of the students among its members. Channels are never recognized by name, so a channel is found again even after the name of the student has changed.
  3. Creates the private channel of each student who does not have one, and renames the channel of each student whose channel does not have the name worked out in the first step.
  4. Adds the student, the instructor and the staff of the course to the 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.
  5. Removes from each student's channel every person who is neither the student, nor the instructor, nor a member of the course staff: for example somebody who has been deleted from the staff of the course. Bots (including the bot this job acts as) and members that are not users of the workspace are never removed. If Slack refuses because of a workspace setting (restricted_action), the log says how to change the setting and no further removals are attempted in that run.
A problem with one channel or one person is logged, and the job carries on with the rest; but if the members of an existing channel cannot be listed, the job stops before changing anything, since it could not tell whose channel that is and might create a duplicate. The last line of the log is a summary.
  • Field Details

    • CHANNEL_PREFIX

      public static final String CHANNEL_PREFIX
      See Also:
    • MAX_CHANNEL_NAME_LENGTH

      public static final int MAX_CHANNEL_NAME_LENGTH
      Slack does not allow longer channel names.
      See Also:
    • NAME_TAKEN

      public static final String NAME_TAKEN
      Slack's error code when a channel (public or private, archived or not) has the name.
      See Also:
    • NAME_TAKEN_ADVICE

      public static final String NAME_TAKEN_ADVICE
      What to tell the instructor when creating a channel fails with NAME_TAKEN.
      See Also:
    • REMOVAL_RESTRICTED_ADVICE

      public static final String REMOVAL_RESTRICTED_ADVICE
      What to tell the instructor when removing a member fails with SlackService.RESTRICTED_ACTION.
      See Also:
    • ENROLLED_STATUSES

      public static final List<RosterStatus> ENROLLED_STATUSES
      Only these roster students are considered: in particular, not dropped students.
  • Constructor Details

    • SetupPrivateSlackChannelsJob

      public SetupPrivateSlackChannelsJob()
  • 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
    • sanitize

      public static String sanitize(String namePart)
      Turns part of a name into the form Slack requires of channel names: accents are dropped, the rest is lowercased, and each run of characters other than letters, numbers and underscores is replaced by one hyphen (none at the start or the end).
      Parameters:
      namePart - for example a last name; may be null
      Returns:
      the sanitized name part; empty if nothing is left
    • firstWord

      public static String firstWord(String firstName)
      Parameters:
      firstName - a first name, possibly followed by middle names; may be null
      Returns:
      the first name up to the first space
    • channelNameFor

      public static String channelNameFor(String firstName, String lastName, String suffix)
      Parameters:
      firstName - the first name; only the part up to the first space is used
      lastName - the last name
      suffix - added at the end, to tell apart students with the same name; may be empty
      Returns:
      the name of the student's private Slack channel, for example private-chris-gaucho
    • 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