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.
- 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. - 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.
- 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.
- 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.
- 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final List<RosterStatus> Only these roster students are considered: in particular, not dropped students.static final intSlack does not allow longer channel names.static final StringSlack's error code when a channel (public or private, archived or not) has the name.static final StringWhat to tell the instructor when creating a channel fails withNAME_TAKEN.static final StringWhat to tell the instructor when removing a member fails withSlackService.RESTRICTED_ACTION. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(edu.ucsb.cs156.jobs.services.JobContext ctx) static StringchannelNameFor(String firstName, String lastName, String suffix) static Stringstatic StringTurns 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).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.ucsb.cs156.jobs.services.JobContextConsumer
getJobName
-
Field Details
-
CHANNEL_PREFIX
- See Also:
-
MAX_CHANNEL_NAME_LENGTH
public static final int MAX_CHANNEL_NAME_LENGTHSlack does not allow longer channel names.- See Also:
-
NAME_TAKEN
Slack's error code when a channel (public or private, archived or not) has the name.- See Also:
-
NAME_TAKEN_ADVICE
What to tell the instructor when creating a channel fails withNAME_TAKEN.- See Also:
-
REMOVAL_RESTRICTED_ADVICE
What to tell the instructor when removing a member fails withSlackService.RESTRICTED_ACTION.- See Also:
-
ENROLLED_STATUSES
Only these roster students are considered: in particular, not dropped students.
-
-
Constructor Details
-
SetupPrivateSlackChannelsJob
public SetupPrivateSlackChannelsJob()
-
-
Method Details
-
getScopeType
- Specified by:
getScopeTypein interfaceedu.ucsb.cs156.jobs.services.JobContextConsumer
-
getScopeId
- Specified by:
getScopeIdin interfaceedu.ucsb.cs156.jobs.services.JobContextConsumer
-
sanitize
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
-
channelNameFor
- Parameters:
firstName- the first name; only the part up to the first space is usedlastName- the last namesuffix- 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
-