Class: GoogleGroup
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GoogleGroup
- Defined in:
- app/models/google_group.rb
Constant Summary
- GDATA_ERROR_ENTRYDOESNOTEXIST =
1301
Instance Attribute Summary (collapse)
-
- (Object) apps_connection
Returns the value of attribute apps_connection.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) establish_apps_connection(force_reconnect = false)
- - (Object) set_values_from_community
- - (Object) update_apps_group
- - (Object) update_apps_group_members
-
- (Object) update_apps_group_owners
owners have to be a member of the group first, so run this after update_apps_group_members.
Instance Attribute Details
- (Object) apps_connection
Returns the value of attribute apps_connection
11 12 13 |
# File 'app/models/google_group.rb', line 11 def apps_connection @apps_connection end |
Class Method Details
+ (Object) clear_errors
151 152 153 |
# File 'app/models/google_group.rb', line 151 def self.clear_errors self.update_all("has_error = 0, last_error = ''","has_error = 1") end |
+ (Object) retrieve_all_groups
146 147 148 149 |
# File 'app/models/google_group.rb', line 146 def self.retrieve_all_groups class_apps_connection = ProvisioningApi.new(AppConfig.configtable['googleapps_account'],AppConfig.configtable['googleapps_secret']) class_apps_connection.retrieve_all_groups end |
Instance Method Details
- (Object) establish_apps_connection(force_reconnect = false)
140 141 142 143 144 |
# File 'app/models/google_group.rb', line 140 def establish_apps_connection(force_reconnect = false) if(self.apps_connection.nil? or force_reconnect) self.apps_connection = ProvisioningApi.new(AppConfig.configtable['googleapps_account'],AppConfig.configtable['googleapps_secret']) end end |
- (Object) set_values_from_community
24 25 26 27 28 29 |
# File 'app/models/google_group.rb', line 24 def set_values_from_community self.group_id = self.community.shortname self.group_name = self.community.name self. = 'Anyone' return true end |
- (Object) update_apps_group
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/google_group.rb', line 31 def update_apps_group self.establish_apps_connection # check for a group - a little different than the google # account check - there's no single group retrieval, so # we'll just check for the apps_updated_at timestamp # create the group if it didn't exist if(self.apps_updated_at.blank?) begin google_group = self.apps_connection.create_group(self.group_id,[self.group_name,self.group_name,self.]) rescue GDataError => e self.update_attributes({:has_error => true, :last_error => e}) return nil end else # update the group begin google_group = self.apps_connection.update_group(self.group_id,[self.group_name,self.group_name,self.]) rescue GDataError => e self.update_attributes({:has_error => true, :last_error => e}) return nil end end self.touch(:apps_updated_at) # if we made it here, it must have worked return google_group end |
- (Object) update_apps_group_members
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/google_group.rb', line 62 def update_apps_group_members # update the group for good measure if(!(google_group = self.update_apps_group)) return nil else # get the members @google begin apps_group_members = self.apps_connection.retrieve_all_members(self.group_id).map(&:member_id) rescue GDataError => e self.update_attributes({:has_error => true, :last_error => e}) return nil end # map the community members to an array of "blah@extension.org" community_members = self.community.joined.map{|u| "#{u.login}@extension.org"} adds = community_members - apps_group_members removes = apps_group_members - community_members # add the adds/remove the removes begin adds.each do |member_id| member = self.apps_connection.add_member_to_group(member_id, self.group_id) end removes.each do |member_id| member = self.apps_connection.remove_member_from_group(member_id, self.group_id) end rescue self.update_attributes({:has_error => true, :last_error => e}) return nil end return google_group end end |
- (Object) update_apps_group_owners
owners have to be a member of the group first, so run this after update_apps_group_members
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/google_group.rb', line 101 def update_apps_group_owners self.establish_apps_connection # get the owners @google begin apps_group_owners = self.apps_connection.retrieve_all_owners(self.group_id).map(&:owner_id) rescue GDataError => e self.update_attributes({:has_error => true, :last_error => e}) return nil end # map the community members to an array of "blah@extension.org" community_owners = self.community.leaders.map{|u| "#{u.login}@extension.org"} adds = community_owners - apps_group_owners removes = apps_group_owners - community_owners results = {:adds => 0, :removes => 0} # add the adds/remove the removes begin adds.each do |owner_id| owner = self.apps_connection.add_owner_to_group(owner_id, self.group_id) results[:adds] += 1 end removes.each do |owner_id| owner = self.apps_connection.remove_owner_from_group(owner_id, self.group_id) results[:removes] += 1 end rescue self.update_attributes({:has_error => true, :last_error => e}) return nil end results end |