lms.djangoapps.teams package

Contents

lms.djangoapps.teams package#

Subpackages#

Submodules#

lms.djangoapps.teams.api module#

The Python API other app should use to work with Teams feature

class lms.djangoapps.teams.api.OrganizationProtectionStatus(*values)#

Bases: Enum

Enum for the different protection status a user can be in related to their course enrollment mode.

“protection_exempt” means the user is a course or org staff that do not need to be protected.

“protected” means the learner is part of an organization and should be in an exclusive team

“unprotected” means the learner is part of the general edX learner in audit or verified tracks

property is_exempt#
property is_protected#
protected = 'org_protected'#
protection_exempt = 'org_protection_exempt'#
unprotected = 'org_unprotected'#
lms.djangoapps.teams.api.add_team_count(user, topics, course_id, organization_protection_status)#

Helper method to add team_count for a list of topics. This allows for a more efficient single query.

lms.djangoapps.teams.api.anonymous_user_ids_for_team(user, team)#

Get the anonymous user IDs for members of a team, used in team submissions Requesting user must be a member of the team or course staff

Returns:

(Array) User IDs, sorted to remove any correlation to usernames

lms.djangoapps.teams.api.can_user_create_team_in_topic(user, course_id, topic_id)#

Returns whether a User has permission to create a team in the given topic.

Assumes that user is enrolled in course run.

lms.djangoapps.teams.api.can_user_modify_team(user, team)#

Returns whether a User has permission to modify the membership of a CourseTeam.

Assumes that user is enrolled in course run.

lms.djangoapps.teams.api.discussion_visible_by_user(discussion_id, user)#

This function checks whether the discussion should be visible to the user. The discussion should not be visible to the user if * The discussion is part of the Team AND * The team is configured to hide the discussions from non-teammembers AND * The user is not part of the team

lms.djangoapps.teams.api.get_assignments_for_team(user, team)#

Get openassessment XBlocks configured for the current teamset

lms.djangoapps.teams.api.get_team_by_discussion(discussion_id)#

This is a function to get team object by the discussion_id passed in. If the discussion_id is not associated with any team, we return None

lms.djangoapps.teams.api.get_team_by_team_id(team_id)#

API Function to lookup team object by team_id, which is globally unique. If there is no such team, return None.

lms.djangoapps.teams.api.get_team_for_user_course_topic(user, course_id, topic_id)#

Returns the matching CourseTeam for the given user, course, and topic

If course_id is invalid, a ValueError is raised

lms.djangoapps.teams.api.get_teams_accessible_by_user(user, topic_id_set, course_id, organization_protection_status)#

Get teams taking for a user, taking into account user visibility privileges

lms.djangoapps.teams.api.get_teams_in_teamset(course_id, topic_id)#

Given a course_id and topic_id, return all CourseTeams in the course and topic

lms.djangoapps.teams.api.has_course_staff_privileges(user, course_key)#

Returns True if the user is an admin for the course, else returns False

lms.djangoapps.teams.api.has_specific_team_access(user, team)#
To have access to a team a user must:
  • Be course staff

OR - be in the correct bubble - be in the team if it is private

lms.djangoapps.teams.api.has_specific_teamset_access(user, course_block, teamset_id)#

Staff have access to all teamsets. All non-staff users have access to open and public_managed teamsets. Non-staff users only have access to a private_managed teamset if they are in a team in that teamset

lms.djangoapps.teams.api.has_team_api_access(user, course_key, access_username=None)#

Returns True if the user has access to the Team API for the course given by course_key. The user must either be enrolled in the course, be course staff, be global staff, or have discussion privileges.

Parameters:
  • user (User) – The user to check access for.

  • course_key (CourseKey) – The key to the course which we are checking access to.

  • access_username (string) – If provided, access_username must match user.username for non staff access.

Returns:

True if the user has access, False otherwise.

Return type:

bool

lms.djangoapps.teams.api.is_instructor_managed_team(team)#

Return true if the team is managed by instructors.

lms.djangoapps.teams.api.is_instructor_managed_topic(course_id, topic)#

Return true if the topic is managed by instructors.

lms.djangoapps.teams.api.is_team_discussion_private(team)#

Checks to see if the team is configured to have its discussion to be private

lms.djangoapps.teams.api.teamset_is_public_or_user_is_on_team_in_teamset(user, course_block, teamset_id)#

The only users who should be able to see private_managed teamsets or recieve any information about them at all from the API are: - Course staff - Users who are enrolled in a team in a private_managed teamset

course_block is passed in because almost universally where we’ll be calling this, we will already need to have looked up the course from modulestore to make sure that the topic we’re interested in exists in the course.

lms.djangoapps.teams.api.user_is_a_team_member(user, team)#

Return if the user is a member of the team If the team is not defined, return False

lms.djangoapps.teams.api.user_on_team_or_team_is_public(user, team)#

The only users who should be able to see private_managed teams or recieve any information about them at all from the API are: - Course staff - Users who are enrolled in a team in a private_managed teamset * They should only be able to see their own team, no other teams.

lms.djangoapps.teams.api.user_organization_protection_status(user, course_key)#

Returns the organization protection status of the user related to this course If the user is in the Masters track of the course, we return the protected status. If the user is a staff of the course, we return the protection_exempt status else, we return the unprotected status

lms.djangoapps.teams.api.user_protection_status_matches_team(user, team)#

Check whether the user have access to the specific team. The user can be of a different organization protection bubble with the team in question. If user is not in the same organization protection bubble with the team, return False. Else, return True. If the user is a course admin, also return true

lms.djangoapps.teams.api_urls module#

Defines the URL routes for the Team API.

lms.djangoapps.teams.csv module#

CSV processing and generation utilities for Teams LMS app.

class lms.djangoapps.teams.csv.TeamMembershipImportManager(course)#

Bases: object

A manager class that is responsible the import process of csv file including validation and creation of team_courseteam and teams_courseteammembership objects.

add_error_and_check_if_max_exceeded(error_message)#

Adds an error to the error collection. :param error_message: :return: True if maximum error threshold is exceeded and processing must stop

False if maximum error threshold is NOT exceeded and processing can continue

add_user_to_team(user_row)#

Creates a CourseTeamMembership entry - i.e: a relationship between a user and a team. user_row is a dictionary where key is column name and value is the row value. {‘mode’: ‘ masters’,’topic_0’: ‘’,’topic_1’: ‘team 2’,’topic_2’: None,’user_model’: <user_obj>}

andrew,masters,team1,,team3

joe,masters,,team2,team3

get_teamset_ids_from_reader(csv_reader)#

The teamsets currently will be directly after ‘mode’

get_user(username)#

Gets the user object from user_name/email/locator user_name: the user_name/email/user locator

property import_succeeded#

Helper wrapper that tells us the status of the import

is_FERPA_bubble_breached(teamset_id, team_name)#

Ensures that FERPA bubble is not breached. Checks that we are not trying to violate FERPA proctection by mixing masters track students with other enrollment tracks.

is_enrollment_protection_for_existing_team_matches_user(user, team_name, teamset_id)#

Applies only to existing teams. Returns True if no violations False if there is a mismatch

is_username_unique(username, usernames_found_so_far)#

Ensures that username exists only once in an input file

load_course_team_memberships()#

Caches existing team memberships by (user_id, teamset_id)

load_course_teams()#

Caches existing course teams by (team_name, topic_id) and existing membership counts by (topic_id, team_name)

remove_user_from_team_for_reassignment(row)#

Remove a user from a team if: a. The user’s current team is different from the team specified in csv for the same teamset (this user will

then be assigned to a new team in ‘add_user_to_team`.

b. The team value in the CSV is blank - the user should be removed from the current team in teamset. Also, if there is no change in user’s membership, the input row’s team name will be nulled out so that no action will take place further in the processing chain.

set_team_membership_from_csv(input_file)#

Parse an input CSV file and pass to set_team_memberships for processing

set_team_memberships(csv_reader)#

Assigns team membership based on the data from an uploaded CSV file. Returns true if there were no issues.

validate_compatible_enrollment_modes(user, team_name, teamset_id)#

Validates that only students enrolled in a masters track are on a single team. Disallows mixing of masters with other enrollment modes on a single team. Masters track students can’t be added to existing non-protected teams

validate_header(csv_reader)#

Validates header row to ensure that it contains at a minimum columns called ‘username’, ‘mode’. Teamset validation is handled separately

validate_team_sizes_not_exceeded()#

Validates that the number of users we want to add to a team won’t exceed maximum team size.

validate_teams_have_matching_teamsets(row)#

It’s possible for a user to create a row that has more team names in it than there are teamset ids provided in the header. In that case, row will have one or more null keys mapping to team names, for example: {‘teamset-1’: ‘team-a’, ‘teamset-2’: ‘team-beta’, None: ‘team-37’}

This method will add a validation error and return False if this is the case.

validate_teamsets(csv_reader)#

Validates team set ids. Returns true if there are no errors. The following conditions result in errors: Teamset does not exist Teamset id is duplicated

validate_user_assignment_to_team_and_teamset(row)#

Validates a user entry relative to an existing team. row is a dictionary where key is column name and value is the row value [andrew],masters,team1,,team3 [joe],masters,,team2,team3

validate_user_enrollment_is_valid(user, supplied_enrollment)#
Invalid states:

user not enrolled in course enrollment mode from csv doesn’t match actual user enrollment

lms.djangoapps.teams.csv.load_team_membership_csv(course, response)#

Load a CSV detailing course membership.

Parameters:
  • course (CourseBlock) – Course block for which CSV download has been requested.

  • response (HttpResponse) – Django response object to which the CSV content will be written.

lms.djangoapps.teams.errors module#

Errors thrown in the Team API.

exception lms.djangoapps.teams.errors.AddToIncompatibleTeamError#

Bases: TeamAPIRequestError

User is enrolled in a mode that is incompatible with this team type. e.g. Masters learners cannot be placed in a team with audit learners

exception lms.djangoapps.teams.errors.AlreadyOnTeamInTeamset#

Bases: TeamAPIRequestError

User is already a member of another team in the same teamset.

exception lms.djangoapps.teams.errors.ElasticSearchConnectionError#

Bases: TeamAPIRequestError

The system was unable to connect to the configured elasticsearch instance.

exception lms.djangoapps.teams.errors.ImmutableMembershipFieldException#

Bases: Exception

An attempt was made to change an immutable field on a CourseTeamMembership model.

exception lms.djangoapps.teams.errors.NotEnrolledInCourseForTeam#

Bases: TeamAPIRequestError

User is not enrolled in the course for the team they are trying to join.

exception lms.djangoapps.teams.errors.TeamAPIRequestError#

Bases: Exception

There was a problem with a request to the Team API.

lms.djangoapps.teams.models module#

Django models related to teams functionality.

class lms.djangoapps.teams.models.CourseTeam(*args, **kwargs)#

Bases: Model

This model represents team related info.

exception DoesNotExist#

Bases: ObjectDoesNotExist

FIELD_BLACKLIST = ['last_activity_at', 'team_size']#
exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

add_user(user)#

Adds the given user to the CourseTeam.

country#
course_id#
classmethod create(name, course_id, description, topic_id='', country='', language='', organization_protected=False)#

Create a complete CourseTeam object.

Parameters:
  • name (str) – The name of the team to be created.

  • course_id (str) – The ID string of the course associated with this team.

  • description (str) – A description of the team.

  • topic_id (str) – An optional identifier for the topic the team formed around.

  • country (str, optional) – An optional country where the team is based, as ISO 3166-1 code.

  • language (str, optional) – An optional language which the team uses, as ISO 639-1 code.

  • organization_protected (bool, optional) – specifies whether the team should only contain members who are in a organization context, or not

date_created#
description#
discussion_topic_id#
field_tracker#
get_country_display(*, field=<django_countries.fields.CountryField: country>)#
get_language_display(*, field=<common.djangoapps.student.models.user.LanguageField: language>)#
get_next_by_date_created(*, field=<django.db.models.fields.DateTimeField: date_created>, is_next=True, **kwargs)#
get_next_by_last_activity_at(*, field=<django.db.models.fields.DateTimeField: last_activity_at>, is_next=True, **kwargs)#
get_previous_by_date_created(*, field=<django.db.models.fields.DateTimeField: date_created>, is_next=False, **kwargs)#
get_previous_by_last_activity_at(*, field=<django.db.models.fields.DateTimeField: last_activity_at>, is_next=False, **kwargs)#
id#
language#
last_activity_at#
membership#

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

name#
objects = <django.db.models.manager.Manager object>#
organization_protected#
refresh_from_db(using=None, fields=None, from_queryset=None)#

Reload field values from the database.

By default, the reloading happens from the database this instance was loaded from, or by the read router if this instance wasn’t loaded from any database. The using parameter will override the default.

Fields can be used to specify which fields to reload. The fields should be an iterable of field attnames. If fields is None, then all non-deferred fields are reloaded.

When accessing deferred fields of an instance, the deferred loading of the field will call this method.

reset_team_size()#

Reset team_size to reflect the current membership count.

save_base(raw=False, force_insert=False, force_update=False, using=None, update_fields=None)#

Handle the parts of saving which should be done only once per save, yet need to be done in raw saves, too. This includes some sanity checks and signal sending.

The ‘raw’ argument is telling save_base not to save any parent models and not to do any changes to the values before save. This is used by fixture loading.

team_id#
team_size#
topic_id#
users#

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class lms.djangoapps.teams.models.CourseTeamMembership(*args, **kwargs)#

Bases: Model

This model represents the membership of a single user in a single team.

exception DoesNotExist#

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned#

Bases: MultipleObjectsReturned

date_joined#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

delete(*args, **kwargs)#

Recompute the related team’s team_size after deleting a membership

classmethod get_memberships(username=None, course_ids=None, team_ids=None)#

Get a queryset of memberships.

Parameters:
  • username (unicode, optional) – The username to filter on.

  • course_ids (list of unicode, optional)

  • team_id (unicode, optional) – The team_id to filter on.

get_next_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=True, **kwargs)#
get_next_by_last_activity_at(*, field=<django.db.models.fields.DateTimeField: last_activity_at>, is_next=True, **kwargs)#
get_previous_by_date_joined(*, field=<django.db.models.fields.DateTimeField: date_joined>, is_next=False, **kwargs)#
get_previous_by_last_activity_at(*, field=<django.db.models.fields.DateTimeField: last_activity_at>, is_next=False, **kwargs)#
id#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

immutable_fields = ('user', 'team', 'date_joined')#
classmethod is_user_on_team(user, team)#

Is user on team?

last_activity_at#

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>#
save(*args, **kwargs)#

Customize save method to set the last_activity_at if it does not currently exist. Also resets the team’s size if this model is being created.

team#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

team_id#
classmethod update_last_activity(user, discussion_topic_id)#

Set the last_activity_at for both this user and their team in the given discussion topic. No-op if the user is not a member of the team for this discussion.

user#

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

user_id#
classmethod user_in_team_for_teamset(user, course_id, topic_id)#

Using the provided teamset_id, checks to see if a user is assigned to any team in the teamset.

Parameters:
  • user – the user that we want to query on

  • course_id – the course_id of the course we’re interested in

  • topic_id – the topic_id of the course we are interested in

Returns:

True if the user is on a team in a teamset in the course already False if not

lms.djangoapps.teams.models.comment_endorsed_handler(sender, **kwargs)#

Update the user’s last activity date upon endorsing a comment.

lms.djangoapps.teams.models.handle_activity(user, post, original_author_id=None)#

Handle user activity from lms.djangoapps.discussion.django_comment_client and discussion.rest_api and update the user’s last activity date. Checks if the user who performed the action is the original author, and that the discussion has the team context.

lms.djangoapps.teams.models.post_create_vote_handler(sender, **kwargs)#

Update the user’s last activity date upon creating or voting for a post.

lms.djangoapps.teams.models.post_edit_delete_handler(sender, **kwargs)#

Update the user’s last activity date upon editing or deleting a post.

lms.djangoapps.teams.models.post_followed_unfollowed_handler(sender, **kwargs)#

Update the user’s last activity date upon followed or unfollowed of a post.

lms.djangoapps.teams.models.utc_now()#

lms.djangoapps.teams.plugins module#

Definition of the course team feature.

class lms.djangoapps.teams.plugins.TeamsCourseApp#

Bases: CourseApp

Course app for teams.

app_id: str = 'teams'#
description: str = 'Leverage teams to allow learners to connect by topic of interest.'#
classmethod get_allowed_operations(course_key: CourseKey, user: User | None = None) Dict[str, bool]#

Return allowed operations for teams app.

classmethod is_available(course_key: CourseKey) bool#

The teams app is currently available globally based on a feature setting.

classmethod is_enabled(course_key: CourseKey) bool#

Returns the enabled status of teams.

Parameters:

course_key (CourseKey) – The course for which to fetch the status of teams

name: str = 'Teams'#
classmethod set_enabled(course_key: CourseKey, enabled: bool, user: User) bool#

Returns the enabled status of teams. :param course_key: The course for which to set the status of teams :type course_key: CourseKey :param enabled: The new satus for the app. :type enabled: bool :param user: The user performing the operation :type user: User

Returns:

the new status of the app

Return type:

(bool)

class lms.djangoapps.teams.plugins.TeamsTab(tab_dict)#

Bases: EnrolledTab

The representation of the course teams view type.

classmethod is_enabled(course, user=None)#

Returns true if the teams feature is enabled in the course.

Parameters:
  • course (CourseBlock) – the course using the feature

  • user (User) – the user interacting with the course

priority = 60#
title = 'Teams'#
type = 'teams'#
view_name = 'teams_dashboard'#

lms.djangoapps.teams.search_indexes module#

Search index used to load data into elasticsearch.

class lms.djangoapps.teams.search_indexes.CourseTeamIndexer(course_team)#

Bases: object

This is the index object for searching and storing CourseTeam model instances.

DOCUMENT_TYPE_NAME = 'course_team'#
ENABLE_SEARCH_KEY = 'ENABLE_TEAMS'#
INDEX_NAME = 'course_team_index'#
content_text()#

Generate the text field used for general search.

data()#

Uses the CourseTeamSerializer to create a serialized course_team object. Adds in additional text and pk fields. Removes membership relation.

Returns serialized object with additional search fields.

classmethod engine()#

Return course team search engine (if feature is enabled).

classmethod index(course_team)#

Update index with course_team object (if feature is enabled).

classmethod remove(course_team)#

Remove course_team from the index (if feature is enabled).

classmethod search_is_enabled()#

Return boolean of whether course team indexing is enabled.

lms.djangoapps.teams.search_indexes.course_team_post_delete_callback(**kwargs)#

Reindex object after delete.

lms.djangoapps.teams.search_indexes.course_team_post_save_callback(**kwargs)#

Reindex object after save.

lms.djangoapps.teams.search_indexes.if_search_enabled(f)#

Only call f if search is enabled for the CourseTeamIndexer.

lms.djangoapps.teams.serializers module#

Defines serializers used by the Team API.

class lms.djangoapps.teams.serializers.BaseTopicSerializer(*args, **kwargs)#

Bases: Serializer

Serializes a topic without team_count.

class lms.djangoapps.teams.serializers.BulkTeamCountTopicListSerializer(*args, **kwargs)#

Bases: ListSerializer

List serializer for efficiently serializing a set of topics.

to_representation(obj)#

Adds team_count to each topic.

class lms.djangoapps.teams.serializers.BulkTeamCountTopicSerializer(*args, **kwargs)#

Bases: BaseTopicSerializer

Serializes a set of topics, adding the team_count field to each topic as a bulk operation. Requires that context is provided with a valid course_id in order to filter teams within the course.

class Meta#

Bases: object

list_serializer_class#

alias of BulkTeamCountTopicListSerializer

class lms.djangoapps.teams.serializers.CountryField(*args, **kwargs)#

Bases: Field

Field to serialize a country code.

COUNTRY_CODES = ['AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BQ', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'CV', 'KH', 'CM', 'CA', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CG', 'CK', 'CR', 'CI', 'HR', 'CU', 'CW', 'CY', 'CZ', 'CD', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'SZ', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT', 'HM', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'XK', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'KP', 'MK', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SX', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'KR', 'SS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'UM', 'US', 'UY', 'UZ', 'VU', 'VA', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW']#
to_internal_value(data)#

Check that the code is a valid country code.

We leave the data in its original format so that the Django model’s CountryField can convert it to the internal representation used by the django-countries library.

to_representation(obj)#

Represent the country as a 2-character unicode identifier.

class lms.djangoapps.teams.serializers.CourseTeamCreationSerializer(*args, **kwargs)#

Bases: ModelSerializer

Deserializes a CourseTeam for creation.

class Meta#

Bases: object

fields = ('name', 'course_id', 'description', 'topic_id', 'country', 'language', 'organization_protected')#
model#

alias of CourseTeam

create(validated_data)#

We have a bit of extra checking around this in order to provide descriptive messages when something goes wrong, but this method is essentially just:

return ExampleModel.objects.create(**validated_data)

If there are many to many fields present on the instance then they cannot be set until the model is instantiated, in which case the implementation is like so:

example_relationship = validated_data.pop(‘example_relationship’) instance = ExampleModel.objects.create(**validated_data) instance.example_relationship = example_relationship return instance

The default implementation also does not handle nested relationships. If you want to support writable nested relationships you’ll need to write an explicit .create() method.

class lms.djangoapps.teams.serializers.CourseTeamSerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializes a CourseTeam with membership information.

class Meta#

Bases: object

fields = ('id', 'discussion_topic_id', 'name', 'course_id', 'topic_id', 'date_created', 'description', 'country', 'language', 'last_activity_at', 'membership', 'organization_protected')#
model#

alias of CourseTeam

read_only_fields = ('course_id', 'date_created', 'discussion_topic_id', 'last_activity_at')#
class lms.djangoapps.teams.serializers.CourseTeamSerializerWithoutMembership(*args, **kwargs)#

Bases: CourseTeamSerializer

The same as the CourseTeamSerializer, but elides the membership field.

Intended to be used as a sub-serializer for serializing team memberships, since the membership field is redundant in that case.

class lms.djangoapps.teams.serializers.MembershipSerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializes CourseTeamMemberships with information about both teams and users.

class Meta#

Bases: object

fields = ('user', 'team', 'date_joined', 'last_activity_at')#
model#

alias of CourseTeamMembership

read_only_fields = ('date_joined', 'last_activity_at')#
profile_configuration = {'admin_fields': ['account_privacy', 'profile_image', 'username', 'bio', 'course_certificates', 'country', 'date_joined', 'language_proficiencies', 'level_of_education', 'social_links', 'time_zone', 'name', 'email', 'id', 'verified_name', 'extended_profile', 'gender', 'state', 'goals', 'is_active', 'last_login', 'mailing_address', 'requires_parental_consent', 'secondary_email', 'secondary_email_enabled', 'year_of_birth', 'phone_number', 'pending_name_change'], 'bulk_shareable_fields': ['account_privacy', 'profile_image', 'username', 'bio', 'course_certificates', 'country', 'date_joined', 'language_proficiencies', 'level_of_education', 'social_links', 'time_zone', 'url'], 'custom_shareable_fields': ['account_privacy', 'profile_image', 'username', 'bio', 'course_certificates', 'country', 'date_joined', 'language_proficiencies', 'level_of_education', 'social_links', 'time_zone', 'name'], 'default_visibility': 'all_users', 'public_fields': ['account_privacy', 'profile_image', 'username', 'url']}#
class lms.djangoapps.teams.serializers.TopicSerializer(*args, **kwargs)#

Bases: BaseTopicSerializer

Adds team_count to the basic topic serializer, checking if team_count is already present in the topic data, and if not, querying the CourseTeam model to get the count. Requires that context is provided with a valid course_id in order to filter teams within the course.

get_team_count(topic)#

Get the number of teams associated with this topic

class lms.djangoapps.teams.serializers.UserMembershipSerializer(*args, **kwargs)#

Bases: ModelSerializer

Serializes CourseTeamMemberships with only user and date_joined

Used for listing team members.

class Meta#

Bases: object

fields = ('user', 'date_joined', 'last_activity_at')#
model#

alias of CourseTeamMembership

read_only_fields = ('date_joined', 'last_activity_at')#
profile_configuration = {'admin_fields': ['account_privacy', 'profile_image', 'username', 'bio', 'course_certificates', 'country', 'date_joined', 'language_proficiencies', 'level_of_education', 'social_links', 'time_zone', 'name', 'email', 'id', 'verified_name', 'extended_profile', 'gender', 'state', 'goals', 'is_active', 'last_login', 'mailing_address', 'requires_parental_consent', 'secondary_email', 'secondary_email_enabled', 'year_of_birth', 'phone_number', 'pending_name_change'], 'bulk_shareable_fields': ['account_privacy', 'profile_image', 'username', 'bio', 'course_certificates', 'country', 'date_joined', 'language_proficiencies', 'level_of_education', 'social_links', 'time_zone', 'url'], 'custom_shareable_fields': ['account_privacy', 'profile_image', 'username', 'bio', 'course_certificates', 'country', 'date_joined', 'language_proficiencies', 'level_of_education', 'social_links', 'time_zone', 'name'], 'default_visibility': 'all_users', 'public_fields': ['account_privacy', 'profile_image', 'username', 'url']}#

lms.djangoapps.teams.services module#

Services to expose the Teams API to XBlocks

class lms.djangoapps.teams.services.TeamsService#

Bases: object

Functions to provide teams functionality to XBlocks

get_anonymous_user_ids_for_team(user, team)#
get_team(user, course_id, topic_id)#
get_team_by_team_id(team_id)#
get_team_detail_url(team)#

Returns the url to the detail view for the given team

get_team_names(course_id, topic_id)#

Given a course and topic id, return a dict mapping from team id to team name for teams in that topic

lms.djangoapps.teams.team_partition_scheme module#

Provides a UserPartition driver for teams.

class lms.djangoapps.teams.team_partition_scheme.TeamPartitionScheme#

Bases: object

Uses course team memberships to map learners into partition groups.

The scheme is only available if the CONTENT_GROUPS_FOR_TEAMS feature flag is enabled.

This is how it works: - A user partition is created for each team-set in the course with a unused partition ID generated in runtime by using generate_int_id() with min=MINIMUM_UNUSED_PARTITION_ID and max=MYSQL_MAX_INT. - A (Content) group is created for each team in the team-set with the database team ID as the group ID, and the team name as the group name. - A user is assigned to a group if they are a member of the team.

classmethod create_user_partition(id, name, description, groups=None, parameters=None, active=True)#

Create a custom UserPartition to support dynamic groups based on teams.

A Partition has an id, name, scheme, description, parameters, and a list of groups. The id is intended to be unique within the context where these are used. (e.g., for partitions of users within a course, the ids should be unique per-course). The scheme is used to assign users into groups. The parameters field is used to save extra parameters e.g., location of the course ID for this partition scheme.

Partitions can be marked as inactive by setting the “active” flag to False. Any group access rule referencing inactive partitions will be ignored when performing access checks.

Parameters:
  • id (int) – The id of the partition.

  • name (str) – The name of the partition.

  • description (str) – The description of the partition.

  • groups (list of Group) – The groups in the partition.

  • parameters (dict) – The parameters for the partition.

  • active (bool) – Whether the partition is active.

Returns:

The user partition.

Return type:

TeamUserPartition

classmethod get_group_for_user(course_key, user, user_partition)#

Get the (Content) Group from the specified user partition for the user.

A user is assigned to the group via their team membership and any mappings from teams to partitions / groups that might exist.

Parameters:
  • course_key (CourseKey) – The course key.

  • user (User) – The user.

  • user_partition (UserPartition) – The user partition.

Returns:

The group in the specified user partition

Return type:

Group

read_only = True#
class lms.djangoapps.teams.team_partition_scheme.TeamUserPartition(id, name, description, groups, scheme=None, parameters=None, active=True, scheme_id='random')#

Bases: UserPartition

Extends UserPartition to support dynamic groups pulled from the current course teams.

property groups#

Dynamically generate groups (based on teams) for this partition.

Returns:

The groups in this partition.

Return type:

list of Group

lms.djangoapps.teams.toggles module#

Togglable settings for Teams behavior

lms.djangoapps.teams.toggles.are_team_submissions_enabled(course_key)#

Checks to see if the CourseWaffleFlag or Django setting for team submissions is enabled

lms.djangoapps.teams.urls module#

Defines the URL routes for this app.

lms.djangoapps.teams.utils module#

Utility methods related to teams.

lms.djangoapps.teams.utils.emit_team_event(event_name, course_key, event_data)#

Emit team events with the correct course id context.

lms.djangoapps.teams.views module#

HTTP endpoints for the Teams API.

class lms.djangoapps.teams.views.HasSpecificTeamAccess#

Bases: BasePermission

Permission that checks if the user has access to a specific team. If the user doesn’t have access to the team, the endpoint should behave as if the team does not exist,

has_object_permission(request, view, obj)#

Return True if permission is granted, False otherwise.

class lms.djangoapps.teams.views.IsEnrolledOrIsStaff#

Bases: BasePermission

Permission that checks to see if the user is enrolled in the course or is staff.

has_object_permission(request, view, obj)#

Returns true if the user is enrolled or is staff.

class lms.djangoapps.teams.views.IsStaffOrPrivilegedOrReadOnly#

Bases: IsStaffOrReadOnly

Permission that checks to see if the user is global staff, course staff, course admin, or has discussion privileges. If none of those conditions are met, only read access will be granted.

has_object_permission(request, view, obj)#

Return True if permission is granted, False otherwise.

class lms.djangoapps.teams.views.MembershipBulkManagementView(**kwargs)#

Bases: GenericAPIView

View for uploading and downloading team membership CSVs.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthentication'>, <class 'rest_framework.authentication.SessionAuthentication'>)#
check_access()#

Raises 403 if user does not have access to this endpoint.

course#

Return a CourseBlock based on the course_id kwarg. If invalid or not found, raise 404.

get(request, **_kwargs)#

Download CSV with team membership data for given course run.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
post(request, **_kwargs)#

Process uploaded CSV to modify team memberships for given course run.

class lms.djangoapps.teams.views.MembershipDetailView(**kwargs)#

Bases: ExpandableFieldViewMixin, GenericAPIView

Use Cases

Gets individual course team memberships or removes a user from a course team.

Example Requests:

GET /api/team/v0/team_membership/{team_id},{username}

DELETE /api/team/v0/team_membership/{team_id},{username}

Query Parameters for GET

  • expand: Comma separated list of types for which to return expanded representations. Supports “user” and “team”.

Response Values for GET

If the user is logged in and enrolled, or is course or global staff the response contains:

  • user: The user associated with the membership. This field may contain an expanded or collapsed representation.

  • team: The team associated with the membership. This field may contain an expanded or collapsed representation.

  • date_joined: The date and time the membership was created.

  • last_activity_at: The date of the last activity of any team member

    within the team.

For all text fields, clients rendering the values should take care to HTML escape them to avoid script injections, as the data is stored exactly as specified. The intention is that plain text is supported, not HTML.

If the user is not logged in and active, a 401 error is returned.

If specified team does not exist, a 404 error is returned.

If the user is logged in but is not enrolled in the course associated with the specified team, or is not staff, a 404 error is returned. This avoids leaking information about course or team existence.

If the membership does not exist, a 404 error is returned.

Response Values for DELETE

Any logged in user enrolled in a course can remove themselves from a team in the course. Course staff, global staff, and discussion privileged users can remove any user from a team. Successfully deleting a membership will return a 204 response with no content.

If the user is not logged in and active, a 401 error is returned.

If the specified team or username does not exist, a 404 error is returned.

If the user is not staff or a discussion privileged user and is attempting to remove another user from a team, a 404 error is returned. This prevents leaking information about team and user existence.

If the membership does not exist, a 404 error is returned.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
delete(request, team_id, username)#

DELETE /api/team/v0/team_membership/{team_id},{username}

get(request, team_id, username)#

GET /api/team/v0/team_membership/{team_id},{username}

get_membership(username, team)#

Returns the membership for the given user and team, or throws Http404 if it does not exist.

get_team(team_id)#

Returns the team with team_id, or throws Http404 if it does not exist.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
serializer_class#

alias of MembershipSerializer

class lms.djangoapps.teams.views.MembershipListView(**kwargs)#

Bases: ExpandableFieldViewMixin, GenericAPIView

Use Cases

List teamset team memberships or add a user to a teamset.

Example Requests:

GET /api/team/v0/team_membership

POST /api/team/v0/team_membership

Query Parameters for GET

At least one of username and team_id must be provided.

  • username: Returns membership records only for the specified user. If the requesting user is not staff then only memberships for teams associated with courses in which the requesting user is enrolled are returned.

  • team_id: Returns only membership records associated with the specified team. The requesting user must be staff or enrolled in the course associated with the team.

  • teamset_id: Returns membership records only for the specified teamset. if teamset_id is specified, course_id must also be specified. teamset_id and team_id are mutually exclusive. For open and public_managed teamsets, the user must be staff or enrolled in the course. For private_managed teamsets, the user must be course staff, or a member of the specified teamset.

  • course_id: Returns membership records only for the specified course. Username must have access to this course, or else team_id must be in this course.

  • page_size: Number of results to return per page.

  • page: Page number to retrieve.

  • expand: Comma separated list of types for which to return expanded representations. Supports “user” and “team”.

Response Values for GET

If the user is logged in and enrolled, the response contains:

  • count: The total number of memberships matching the request.

  • next: The URL to the next page of results, or null if this is the last page.

  • previous: The URL to the previous page of results, or null if this is the first page.

  • num_pages: The total number of pages in the result.

  • results: A list of the memberships matching the request.

    • user: The user associated with the membership. This field may contain an expanded or collapsed representation.

    • team: The team associated with the membership. This field may contain an expanded or collapsed representation.

    • date_joined: The date and time the membership was created.

    • last_activity_at: The date of the last activity of the user within the team.

For all text fields, clients rendering the values should take care to HTML escape them to avoid script injections, as the data is stored exactly as specified. The intention is that plain text is supported, not HTML.

If the user is not logged in and active, a 401 error is returned.

If neither team_id nor username are provided, a 400 error is returned.

If team_id is provided but the team does not exist, a 404 error is returned.

If the specified course_id is invalid, a 404 error is returned.

This endpoint uses 404 error codes to avoid leaking information about team or user existence. Specifically, a 404 error will be returned if a logged in user specifies a team_id for a course they are not enrolled in.

Additionally, when username is specified the list of returned memberships will be filtered to memberships in teams associated with courses that the requesting user is enrolled in.

If the course specified by course_id does not contain the team specified by team_id, a 400 error is returned.

If the user is not enrolled in the course specified by course_id, and does not have staff access to the course, a 400 error is returned.

Response Values for POST

Any logged in user enrolled in a course can enroll themselves in a team in the course. Course staff, global staff, and discussion privileged users can enroll any user in a team, with a few exceptions noted below.

If the user is not logged in and active, a 401 error is returned.

If username and team are not provided in the posted JSON, a 400 error is returned describing the missing fields.

If the specified team does not exist, a 404 error is returned.

If the user is not staff, does not have discussion privileges, and is not enrolled in the course associated with the team they are trying to join, or if they are trying to add a user other than themselves to a team, a 404 error is returned. This is to prevent leaking information about the existence of teams and users.

If the specified user does not exist, a 404 error is returned.

If the user is already a member of a team in the course associated with the team they are trying to join, a 400 error is returned. This applies to both staff and students.

If the user is not enrolled in the course associated with the team they are trying to join, a 400 error is returned. This can occur when a staff or discussion privileged user posts a request adding another user to a team.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request)#

GET /api/team/v0/team_membership

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
post(request)#

POST /api/team/v0/team_membership

serializer_class#

alias of MembershipSerializer

class lms.djangoapps.teams.views.MyTeamsPagination#

Bases: DefaultPagination

Paginate the user’s teams.

page_size = 5#
class lms.djangoapps.teams.views.TeamsAssignmentsView(**kwargs)#

Bases: GenericAPIView

Use Cases

Get a team’s assignments

Example Requests:

GET /api/team/v0/teams/{team_id}/assignments

Response Values for GET

If the user is logged in, the response is an array of the following data strcuture:

  • display_name: The name of the assignment to display (currently the Unit title)

  • location: The jump link to a specific assignments

For all text fields, clients rendering the values should take care to HTML escape them to avoid script injections, as the data is stored exactly as specified. The intention is that plain text is supported, not HTML.

If team assignments are not enabled for course, a 503 is returned.

If the user is not logged in, a 401 error is returned.

If the user is unenrolled or does not have API access, a 403 error is returned.

If the supplied course/team is bad or the user is not permitted to search in a protected team, a 404 error is returned as if the team does not exist.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request, team_id)#

GET v0/teams/{team_id_pattern}/assignments

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'lms.djangoapps.teams.views.IsEnrolledOrIsStaff'>, <class 'lms.djangoapps.teams.views.HasSpecificTeamAccess'>, <class 'lms.djangoapps.teams.views.IsStaffOrPrivilegedOrReadOnly'>)#
class lms.djangoapps.teams.views.TeamsDashboardView(**kwargs)#

Bases: GenericAPIView

View methods related to the teams dashboard.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request, course_id)#

Renders the teams dashboard, which is shown on the “Teams” tab.

Raises a 404 if the course specified by course_id does not exist, the user is not registered for the course, or the teams feature is not enabled.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
class lms.djangoapps.teams.views.TeamsDetailView(**kwargs)#

Bases: ExpandableFieldViewMixin, RetrievePatchAPIView

Use Cases

Get, update, or delete a course team’s information. Updates are supported only through merge patch.

Example Requests:

GET /api/team/v0/teams/{team_id}}

PATCH /api/team/v0/teams/{team_id} “application/merge-patch+json”

DELETE /api/team/v0/teams/{team_id}

Query Parameters for GET

  • expand: Comma separated list of types for which to return expanded representations. Supports “user” and “team”.

Response Values for GET

If the user is logged in, the response contains the following fields:

  • id: The team’s unique identifier.

  • discussion_topic_id: The unique id of the comments service discussion topic associated with this team.

  • name: The name of the team.

  • course_id: The identifier for the course this team belongs to.

  • topic_id: Optionally specifies which topic the team is associated with.

  • date_created: Date and time when the team was created.

  • description: A description of the team.

  • country: Optionally specifies which country the team is associated with.

  • language: Optionally specifies which language the team is associated with.

  • membership: A list of the users that are members of the team. See membership endpoint for more detail.

  • last_activity_at: The date of the last activity of any team member within the team.

  • organization_protected: Whether the team consists of organization-protected learners

For all text fields, clients rendering the values should take care to HTML escape them to avoid script injections, as the data is stored exactly as specified. The intention is that plain text is supported, not HTML.

If the user is not logged in, a 401 error is returned.

If the user is not course or global staff, a 403 error is returned.

If the specified team does not exist, a 404 error is returned.

Response Values for PATCH

Only staff can patch teams.

If the user is anonymous or inactive, a 401 is returned.

If the user is logged in and the team does not exist, a 404 is returned. If the user is not course or global staff, does not have discussion privileges, and the team does exist, a 403 is returned.

If “application/merge-patch+json” is not the specified content type, a 415 error is returned.

If the update could not be completed due to validation errors, this method returns a 400 error with all error messages in the “field_errors” field of the returned JSON.

Response Values for DELETE

Only staff can delete teams. When a team is deleted, all team memberships associated with that team are also deleted. Returns 204 on successful deletion.

If the user is anonymous or inactive, a 401 is returned.

If the user is not course or global staff and does not have discussion privileges, a 403 is returned.

If the user is logged in and the team does not exist, a 404 is returned.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
delete(request, team_id)#

DELETE /api/team/v0/teams/{team_id}

get_queryset()#

Returns the queryset used to access the given team.

lookup_field = 'team_id'#
parser_classes = (<class 'openedx.core.lib.api.parsers.MergePatchParser'>,)#
permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>, <class 'lms.djangoapps.teams.views.IsEnrolledOrIsStaff'>, <class 'lms.djangoapps.teams.views.HasSpecificTeamAccess'>, <class 'lms.djangoapps.teams.views.IsStaffOrPrivilegedOrReadOnly'>)#
serializer_class#

alias of CourseTeamSerializer

class lms.djangoapps.teams.views.TeamsListView(**kwargs)#

Bases: ExpandableFieldViewMixin, GenericAPIView

Use Cases

Get or create a course team.

Example Requests:

GET /api/team/v0/teams

POST /api/team/v0/teams

Query Parameters for GET

  • course_id: Filters the result to teams belonging to the given course. Required.

  • topic_id: Filters the result to teams associated with the given topic.

  • text_search: Searches for full word matches on the name, description, country, and language fields. NOTES: Search is on full names for countries and languages, not the ISO codes. Text_search cannot be requested along with with order_by.

  • order_by: Cannot be called along with with text_search. Must be one of the following:

    • name: Orders results by case insensitive team name (default).

    • open_slots: Orders results by most open slots (for tie-breaking, last_activity_at is used, with most recent first).

    • last_activity_at: Orders result by team activity, with most active first (for tie-breaking, open_slots is used, with most open slots first).

  • username: Return teams whose membership contains the given user.

  • page_size: Number of results to return per page.

  • page: Page number to retrieve.

  • expand: Comma separated list of types for which to return expanded representations. Supports “user” and “team”.

Response Values for GET

If the user is logged in and enrolled, the response contains:

  • count: The total number of teams matching the request.

  • next: The URL to the next page of results, or null if this is the last page.

  • previous: The URL to the previous page of results, or null if this is the first page.

  • num_pages: The total number of pages in the result.

  • results: A list of the teams matching the request.

    • id: The team’s unique identifier.

    • discussion_topic_id: The unique id of the comments service discussion topic associated with this team.

    • name: The name of the team.

    • course_id: The identifier for the course this team belongs to.

    • topic_id: Optionally specifies which topic the team is associated with.

    • date_created: Date and time when the team was created.

    • description: A description of the team.

    • country: Optionally specifies which country the team is associated with.

    • language: Optionally specifies which language the team is associated with.

    • last_activity_at: The date of the last activity of any team member within the team.

    • membership: A list of the users that are members of the team. See membership endpoint for more detail.

    • organization_protected: Whether the team consists of organization-protected learners

For all text fields, clients rendering the values should take care to HTML escape them to avoid script injections, as the data is stored exactly as specified. The intention is that plain text is supported, not HTML.

If the user is not logged in, a 401 error is returned.

If the user is not enrolled in the course specified by course_id or is not course or global staff, a 403 error is returned.

If the specified course_id is not valid or the user attempts to use an unsupported query parameter, a 400 error is returned.

If the response does not exist, a 404 error is returned. For example, the course_id may not reference a real course or the page number may be beyond the last page.

If the server is unable to connect to Elasticsearch, and the text_search parameter is supplied, a 503 error is returned.

If the requesting user is a learner, the learner would only see organization protected set of teams if the learner is enrolled in a degree bearing institution. Otherwise, the learner will only see organization unprotected set of teams.

Response Values for POST

Any logged in user who has verified their email address can create a team in an open teamset. The format mirrors that of a GET for an individual team, but does not include the id, date_created, or membership fields. id is automatically computed based on name.

If the user is not logged in, a 401 error is returned.

If the user is not enrolled in the course, is not course or global staff, or does not have discussion privileges a 403 error is returned.

If the course_id is not valid, or the topic_id is missing, or extra fields are included in the request, a 400 error is returned.

If the specified course does not exist, a 404 error is returned. If the specified teamset does not exist, a 404 error is returned. If the specified teamset does exist, but the requesting user shouldn’t be able to see it, a 404 is returned.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request)#

GET /api/team/v0/teams/

get_page()#

Returns page number specified in args, params, or defaults to 1.

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
post(request)#

POST /api/team/v0/teams/

serializer_class#

alias of CourseTeamSerializer

class lms.djangoapps.teams.views.TopicDetailView(**kwargs)#

Bases: APIView

Use Cases

Retrieve a single topic from a course.

Example Requests

GET /api/team/v0/topics/{topic_id},{course_id}

Query Parameters for GET

  • topic_id: The ID of the topic to retrieve (required).

  • course_id: The ID of the course to retrieve the topic from (required).

Response Values for GET

If the user is not logged in, a 401 error is returned.

If the topic_id course_id are not given or an unsupported value is passed for order_by, returns a 400 error.

If the user is not enrolled in the course, or is not course or global staff, returns a 403 error.

If the course does not exist, returns a 404 error.

Otherwise, a 200 response is returned containing the following fields:

  • id: The topic’s unique identifier.

  • name: The name of the topic.

  • description: A description of the topic.

  • team_count: Number of teams created under the topic. If the requesting user

    is enrolled into a degree bearing institution, the count only include the teams with organization_protected attribute true. If the requesting user is not affiliated with any institutions, the teams included in the count would only be those teams whose members are outside of institutions affliation.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request, topic_id, course_id)#

GET /api/team/v0/topics/{topic_id},{course_id}/

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
class lms.djangoapps.teams.views.TopicListView(**kwargs)#

Bases: GenericAPIView

Use Cases

Retrieve a list of topics associated with a single course.

Example Requests

GET /api/team/v0/topics/?course_id={course_id}

Query Parameters for GET

  • course_id: Filters the result to topics belonging to the given course (required).

  • order_by: Orders the results. Currently only ‘name’ and ‘team_count’ are supported; the default value is ‘name’. If ‘team_count’ is specified, topics are returned first sorted by number of teams per topic (descending), with a secondary sort of ‘name’.

  • page_size: Number of results to return per page.

  • page: Page number to retrieve.

Response Values for GET

If the user is not logged in, a 401 error is returned.

If the course_id is not given or an unsupported value is passed for order_by, returns a 400 error.

If the user is not logged in, is not enrolled in the course, or is not course or global staff, returns a 403 error.

If the course does not exist, returns a 404 error.

Otherwise, a 200 response is returned containing the following fields:

  • count: The total number of topics matching the request.

  • next: The URL to the next page of results, or null if this is the last page.

  • previous: The URL to the previous page of results, or null if this is the first page.

  • num_pages: The total number of pages in the result.

  • results: A list of the topics matching the request.

    • id: The topic’s unique identifier.

    • name: The name of the topic.

    • description: A description of the topic.

    • team_count: Number of teams created under the topic. If the requesting user is enrolled into a degree bearing institution, the count only include the teams with organization_protected attribute true. If the requesting user is not affiliated with any institutions, the teams included in the count would only be those teams whose members are outside of institutions affliation.

authentication_classes = (<class 'openedx.core.lib.api.authentication.BearerAuthenticationAllowInactiveUser'>, <class 'edx_rest_framework_extensions.auth.session.authentication.SessionAuthenticationAllowInactiveUser'>)#
get(request)#

GET /api/team/v0/topics/?course_id={course_id}

pagination_class#

alias of TopicsPagination

permission_classes = (<class 'rest_framework.permissions.IsAuthenticated'>,)#
queryset = []#
class lms.djangoapps.teams.views.TopicsPagination#

Bases: DefaultPagination

Paginate topics.

page_size = 12#
lms.djangoapps.teams.views.get_alphabetical_topics(course_block)#

Return a list of team topics sorted alphabetically.

Parameters:

course_block (xblock) – the course which owns the team topics

Returns:

a list of sorted team topics

Return type:

list

lms.djangoapps.teams.views.team_post_save_callback(sender, instance, **kwargs)#

Emits signal after the team is saved.

lms.djangoapps.teams.waffle module#

This module contains various configuration settings via waffle switches for the teams app.

Module contents#

Defines common methods shared by Teams classes

lms.djangoapps.teams.is_feature_enabled(course)#

Returns True if the teams feature is enabled.