2011-02-01 09:57:29 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2011 Instructure, Inc.
|
|
|
|
#
|
|
|
|
# This file is part of Canvas.
|
|
|
|
#
|
|
|
|
# Canvas is free software: you can redistribute it and/or modify it under
|
|
|
|
# the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
# Software Foundation, version 3 of the License.
|
|
|
|
#
|
|
|
|
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License along
|
|
|
|
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2012-01-04 04:30:49 +08:00
|
|
|
module Api::V1::Group
|
|
|
|
include Api::V1::Json
|
2011-02-01 09:57:29 +08:00
|
|
|
|
2012-05-30 06:55:40 +08:00
|
|
|
API_GROUP_JSON_OPTS = {
|
|
|
|
:only => %w(id name description is_public join_level group_category_id),
|
|
|
|
:methods => %w(members_count),
|
|
|
|
}
|
|
|
|
|
2012-06-02 03:18:32 +08:00
|
|
|
API_GROUP_MEMBERSHIP_JSON_OPTS = {
|
|
|
|
:only => %w(id group_id user_id workflow_state moderator)
|
|
|
|
}
|
|
|
|
|
2012-01-04 04:30:49 +08:00
|
|
|
def group_json(group, user, session, options = {})
|
2012-05-30 06:55:40 +08:00
|
|
|
hash = api_json(group, user, session, API_GROUP_JSON_OPTS)
|
2012-06-06 03:57:22 +08:00
|
|
|
followed = ::UserFollow.followed_by_user([group], user)
|
|
|
|
hash['followed_by_user'] = !!followed.include?(group)
|
2012-06-02 00:24:41 +08:00
|
|
|
image = group.avatar_attachment
|
|
|
|
hash['avatar_url'] = image && thumbnail_image_url(image, image.uuid)
|
2012-01-04 04:30:49 +08:00
|
|
|
include = options[:include] || []
|
|
|
|
if include.include?('users')
|
|
|
|
hash['users'] = group.users.map{ |u| user_json(u, user, session) }
|
|
|
|
end
|
|
|
|
hash
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
2012-06-02 03:18:32 +08:00
|
|
|
|
|
|
|
def group_membership_json(membership, user, session)
|
|
|
|
api_json(membership, user, session, API_GROUP_MEMBERSHIP_JSON_OPTS)
|
|
|
|
end
|
2011-02-01 09:57:29 +08:00
|
|
|
end
|
|
|
|
|