nakamura 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'logger'
4
+
5
+ module SlingAuthz
6
+
7
+ class Authz
8
+
9
+ attr_accessor :log
10
+
11
+ def initialize(sling)
12
+ @sling = sling
13
+ @log = Logger.new(STDOUT)
14
+ @log.level = Logger::WARN
15
+ end
16
+
17
+ def delete(path,principal)
18
+ postParams = {}
19
+ postParams[':applyTo'] = [principal]
20
+ urlpath = @sling.url_for(path)
21
+ res = @sling.execute_post(urlpath+".deleteAce.html", postParams)
22
+ if ( res.code != "200" )
23
+ @log.debug(res.body)
24
+ @log.info(" Unable to update acl at #{path} "+postParams)
25
+ return false
26
+ end
27
+
28
+ end
29
+
30
+ def grant(path,principal,privilege)
31
+
32
+ acl = getacl(path)
33
+ ace = {}
34
+ if ( acl[principal] )
35
+ @log.info(acl[principal])
36
+ ace = acl[principal]
37
+ end
38
+ postParams = {}
39
+ postParams['principalId'] = principal
40
+
41
+ # Save the current ACE
42
+ ace.each do | key, value |
43
+ if ( key == "granted" || key == "denied" )
44
+ value.each do | priv |
45
+ postParams['privilege@'+priv] = key
46
+ end
47
+ end
48
+ end
49
+
50
+ # Add in the new ACE
51
+ privilege.each do | key, value |
52
+ postParams['privilege@'+key] = value
53
+ end
54
+
55
+ @log.info("Updating ACE to :"+hashToString(postParams))
56
+
57
+
58
+ urlpath = @sling.url_for(path)
59
+ res = @sling.execute_post(urlpath+".modifyAce.html", postParams)
60
+ if ( res.code != "200" )
61
+ @log.debug(res.body)
62
+ @log.info(" Unable to update acl at #{path} "+postParams)
63
+ return false
64
+ end
65
+ end
66
+
67
+ def getacl(path)
68
+ urlpath = @sling.url_for(path)
69
+ res = @sling.execute_get(urlpath+".acl.json")
70
+ if ( res.code != "200" )
71
+ log.info(" Unable to get ACL at path #{path} ")
72
+ return false
73
+ end
74
+ @log.info("Current ACE :"+res.body)
75
+
76
+ acl = JSON.parse(res.body)
77
+ return acl
78
+ end
79
+
80
+ def hashToString(hashVar)
81
+ fs = "{"
82
+ hashVar.each do | key, value |
83
+ fs = fs + '"' + key + '" => "'+value.to_s+'",'
84
+ end
85
+ fs = fs + "}"
86
+ end
87
+
88
+
89
+
90
+ end
91
+
92
+
93
+ end
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module SlingContacts
4
+
5
+ class ContactManager
6
+
7
+ def initialize(sling)
8
+ @sling = sling
9
+ end
10
+
11
+ def invite_contact(name, sharedRelationships, fromRelationships=[], toRelationships=[])
12
+ case sharedRelationships
13
+ when String
14
+ sharedRelationships = [sharedRelationships]
15
+ end
16
+ home = @sling.get_user().home_path_for(@sling)
17
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.invite.html"), "sakai:types" => sharedRelationships,
18
+ "fromRelationships" => fromRelationships, "toRelationships" => toRelationships, "targetUserId" => name)
19
+ end
20
+
21
+ def accept_contact(name)
22
+ home = @sling.get_user().home_path_for(@sling)
23
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.accept.html"), {"targetUserId" => name})
24
+ end
25
+
26
+ def reject_contact(name)
27
+ home = @sling.get_user().home_path_for(@sling)
28
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.reject.html"), {"targetUserId" => name})
29
+ end
30
+
31
+ def ignore_contact(name)
32
+ home = @sling.get_user().home_path_for(@sling)
33
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.ignore.html"), {"targetUserId" => name})
34
+ end
35
+
36
+ def block_contact(name)
37
+ home = @sling.get_user().home_path_for(@sling)
38
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.block.html"), {"targetUserId" => name})
39
+ end
40
+
41
+ def remove_contact(name)
42
+ home = @sling.get_user().home_path_for(@sling)
43
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.remove.html"), {"targetUserId" => name})
44
+ end
45
+
46
+ def cancel_invitation(name)
47
+ home = @sling.get_user().home_path_for(@sling)
48
+ return @sling.execute_post(@sling.url_for("#{home}/contacts.cancel.html"), {"targetUserId" => name})
49
+ end
50
+
51
+
52
+ def get_accepted()
53
+ return find_contacts("ACCEPTED")
54
+ end
55
+
56
+ def get_pending()
57
+ return find_contacts("PENDING")
58
+ end
59
+
60
+ def get_invited()
61
+ return find_contacts("INVITED")
62
+ end
63
+
64
+ def get_blocked()
65
+ return find_contacts("BLOCKED")
66
+ end
67
+
68
+ def get_ignored()
69
+ return find_contacts("IGNORED")
70
+ end
71
+
72
+ def get_all()
73
+ return find_contacts("*%3A*")
74
+ end
75
+
76
+ def find_contacts(state)
77
+ result = @sling.execute_get(@sling.url_for("var/contacts/findstate?state=#{state}"))
78
+ return JSON.parse(result.body)
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module SlingFile
4
+
5
+ $testfile1 = "<html><head><title>KERN 312</title></head><body><p>Should work</p></body></html>"
6
+
7
+ class FileManager
8
+
9
+ def initialize(sling)
10
+ @sling = sling
11
+ end
12
+
13
+ def createlink(url, linkUid, siteUuid)
14
+ props = {
15
+ ":operation" => "link",
16
+ "link" => linkUid
17
+ }
18
+ if (siteUuid != nil)
19
+ props.update("site" => siteUuid)
20
+ end
21
+ return @sling.execute_post(@sling.url_for(url), props)
22
+ end
23
+
24
+ def createTag(tagName, url, props = {})
25
+ props.update("sling:resourceType" => "sakai/tag")
26
+ props.update("sakai:tag-name" => tagName)
27
+ return @sling.execute_post(@sling.url_for(url), props)
28
+ end
29
+
30
+ def tag(url, tagUuid)
31
+ props = {
32
+ ":operation" => "tag",
33
+ "key" => tagUuid
34
+ }
35
+ return @sling.execute_post(@sling.url_for(url), props)
36
+ end
37
+
38
+ def myfiles(search)
39
+ return @sling.execute_get(@sling.url_for("/var/search/files/myfiles.json?q=#{search}"))
40
+ end
41
+
42
+ def upload_pooled_file(name, data, content_type, toid=nil)
43
+ if ( toid == nil )
44
+ return @sling.execute_file_post(@sling.url_for("/system/pool/createfile"), name, name, data, content_type)
45
+ else
46
+ return @sling.execute_file_post(@sling.url_for("/system/pool/createfile.#{toid}"), name, name, data, content_type)
47
+ end
48
+ end
49
+
50
+ def url_for_pooled_file(id)
51
+ return @sling.url_for("/p/#{id}")
52
+ end
53
+
54
+ # Members
55
+ def get_members(id)
56
+ path = "#{url_for_pooled_file(id)}.members.json"
57
+ return @sling.execute_get(path)
58
+ end
59
+
60
+ def manage_members(id, add_viewers, delete_viewers, add_managers, delete_managers)
61
+ path = "#{url_for_pooled_file(id)}.members.html"
62
+ params = {}
63
+ params[":viewer"] ||= add_viewers
64
+ params[":viewer@Delete"] ||= delete_viewers
65
+ params[":manager"] ||= add_managers
66
+ params[":manager@Delete"] ||= delete_managers
67
+ return @sling.execute_post(path, params)
68
+ end
69
+
70
+ # Search templates
71
+
72
+ def search_my_managed(q)
73
+ return @sling.execute_get(@sling.url_for("/var/search/pool/me/manager.json?q=#{q}"))
74
+ end
75
+
76
+ def search_my_viewed(q)
77
+ return @sling.execute_get(@sling.url_for("/var/search/pool/me/viewer.json?q=#{q}"))
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,290 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # work on KERN-1881 to duplicate all 11 to 13 POSTs that go into creating a group
4
+
5
+ require 'json'
6
+ require 'nakamura'
7
+ require 'nakamura/users'
8
+ require 'nakamura/file'
9
+ include SlingInterface
10
+ include SlingUsers
11
+ include SlingFile
12
+
13
+ $FULL_GROUP_URI="#{$USERMANAGER_URI}group.create.json"
14
+ $BATCH_URI = "system/batch"
15
+
16
+ module SlingUsers
17
+
18
+ # a subclass of the library UserManager for creating fully featured groups
19
+ # unlike the skeleton groups that super.create_group creates
20
+ class FullGroupCreator < UserManager
21
+ attr_reader :log, :file_log
22
+
23
+ def initialize(sling, file_log = nil)
24
+ @sling = sling
25
+ @sling.log.level = Logger::INFO
26
+ #@sling.do_login
27
+ #@user_manager = UserManager.new(@sling)
28
+ super sling
29
+ @log.level = Logger::INFO
30
+ @file_log = file_log
31
+ end
32
+
33
+ # this method follows the series of POSTs that the UI makes to create a group with a
34
+ # full set of features including the initial sakai doce for Library and Participants
35
+ def create_full_group(creator_id, groupname, title = nil, description = nil)
36
+ creator = User.new(creator_id, "testuser")
37
+ @sling.switch_user(creator)
38
+ #POST 1 - creating the manager sub-group
39
+ create_pseudo_group(groupname + "-manager", groupname + " Manager", description)
40
+
41
+ #POST 2 - creating the member sub-group
42
+ create_pseudo_group(groupname + "-member", groupname + " Member", description)
43
+
44
+ #POST 3 creating the main group
45
+ group = create_target_group(groupname, title, description) #POST 3
46
+
47
+ update_uri = "/#{$USERMANAGER_URI}group/"
48
+
49
+ #POST 4 - updating the group managers
50
+ batch_post = []
51
+ batch_post[0] = {"url" => "#{update_uri}#{groupname}-member.update.json", "method" => "POST", "parameters" => {":manager" => "#{groupname}-manager","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
52
+ batch_post[1] = {"url" => "#{update_uri}#{groupname}-manager.update.json", "method" => "POST", "parameters" => {":manager" => "#{groupname}-manager","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
53
+ batch_post[2] = {"url" => "#{update_uri}#{groupname}.update.json", "method" => "POST", "parameters" => {":manager" => "#{groupname}-manager","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
54
+ batch_post_json = JSON.generate batch_post
55
+ @log.debug("POST 4 - updating the group managersbatch post is: #{batch_post_json}")
56
+ @file_log.debug("POST 4 - updating the group managersbatch post is: #{batch_post_json}") if (@file_log)
57
+ parameters = {"requests" => batch_post_json}
58
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
59
+ @log.info("POST 4 - updating the group managers response code is: #{response.code}")
60
+ @file_log.info("POST 4 - updating the group managers response code is: #{response.code}") if (@file_log)
61
+
62
+ #POST 5 - updating the group members
63
+ batch_post = []
64
+ batch_post[0] = {"url" => "#{update_uri}#{groupname}-manager.update.json", "method" => "POST", "parameters" => {":member" => "#{creator_id}", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
65
+ batch_post[1] = {"url" => "#{update_uri}#{groupname}.update.json", "method" => "POST", "parameters" => {":member" => "#{groupname}-member", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
66
+ batch_post[2] = {"url" => "#{update_uri}#{groupname}.update.json", "method" => "POST", "parameters" => {":member" => "#{groupname}-manager", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
67
+ batch_post_json = JSON.generate batch_post
68
+ @log.debug("POST 5 - updating the group members batch post is: #{batch_post_json}")
69
+ @file_log.debug("POST 5 - updating the group members batch post is: #{batch_post_json}") if (@file_log)
70
+ parameters = {"requests" => batch_post_json}
71
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
72
+ @log.info("POST 5 - updating the group members response code is: #{response.code}")
73
+ @file_log.info("POST 5 - updating the group members response code is: #{response.code}") if (@file_log)
74
+
75
+ #POST 6 - creating test tags
76
+ batch_post = []
77
+ batch_post[0] = {"url" => "/tags/test-tag1", "method" => "POST", "parameters" => {"sakai:tag-name" => "test-tag1", "sling:resourceType" => "sakai/tag", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
78
+ batch_post[1] = {"url" => "/tags/test-tag2", "method" => "POST", "parameters" => {"sakai:tag-name" => "test-tag2", "sling:resourceType" => "sakai/tag", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
79
+ batch_post_json = JSON.generate batch_post
80
+ @log.debug("POST 6 - creating test tags batch post is: #{batch_post_json}")
81
+ @file_log.debug("POST 6 - creating test tags batch post is: #{batch_post_json}") if (@file_log)
82
+ parameters = {"requests" => batch_post_json}
83
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
84
+ @log.info("POST 6 - creating test tags response code is: #{response.code}")
85
+ @file_log.info("POST 6 - creating test tags response code is: #{response.code}") if (@file_log)
86
+
87
+ #POST 7 - updating group visibility, joinability and permissions
88
+ batch_post = []
89
+ batch_post[0] = {"url" => "#{update_uri}#{groupname}.update.html", "method" => "POST", "parameters" => {"rep:group-viewers@Delete" => "", "sakai:group-visible" => "public", "sakai:group-joinable" => "yes", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
90
+ batch_post[1] = {"url" => "/~#{groupname}.modifyAce.html", "method" => "POST", "parameters" => {"principalId" => "everyone", "privilege@jcr:read" => "granted", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
91
+ batch_post[2] = {"url" => "/~#{groupname}.modifyAce.html", "method" => "POST", "parameters" => {"principalId" => "anonymous", "privilege@jcr:read" => "granted", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
92
+ batch_post_json = JSON.generate batch_post
93
+ @log.debug("POST 7 - updating group visibility, joinability and permissions batch post is: #{batch_post_json}")
94
+ @file_log.debug("POST 7 - updating group visibility, joinability and permissions batch post is: #{batch_post_json}") if (@file_log)
95
+ parameters = {"requests" => batch_post_json}
96
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
97
+ @log.info("POST 7 - updating group visibility, joinability and permissions response code is: #{response.code}")
98
+ @file_log.info("POST 7 - updating group visibility, joinability and permissions response code is: #{response.code}") if (@file_log)
99
+
100
+ #POST 8 - creating initial sakai docs
101
+ batch_post = []
102
+ batch_post[0] = {"url" => "/system/pool/createfile", "method" => "POST", "parameters" => {"sakai:pooled-content-file-name" => "Library", "sakai:description" => "", "sakai:permissions" => "public", "sakai:copyright" => "creativecommons", \
103
+ "structure0" => "{\"library\":{\"_ref\":\"id9867543247\",\"_order\":0,\"_nonEditable\":true,\"_title\":\"Library\",\"main\":{\"_ref\":\"id9867543247\",\"_order\":0,\"_nonEditable\":true,\"_title\":\"Library\"}}}", \
104
+ "mimeType" => "x-sakai/document","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
105
+
106
+ batch_post[1] = {"url" => "/system/pool/createfile", "method" => "POST", "parameters" => {"sakai:pooled-content-file-name" => "Participants", "sakai:description" => "", "sakai:permissions" => "public", "sakai:copyright" => "creativecommons", \
107
+ "structure0" => "{\"participants\":{\"_ref\":\"id6573920372\",\"_order\":0,\"_nonEditable\":true,\"_title\":\"Participants\",\"main\":{\"_ref\":\"id6573920372\",\"_order\":0,\"_nonEditable\":true,\"_title\":\"Participants\"}}}", \
108
+ "mimeType" => "x-sakai/document","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
109
+ batch_post_json = JSON.generate batch_post
110
+ @log.debug("#POST 8 - creating initial sakai docs batch post is: #{batch_post_json}")
111
+ @file_log.debug("#POST 8 - creating initial sakai docs batch post is: #{batch_post_json}") if (@file_log)
112
+ parameters = {"requests" => batch_post_json}
113
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
114
+ @log.info("POST 8 - creating initial sakai docs response code is: #{response.code}")
115
+ @file_log.info("POST 8 - creating initial sakai docs response code is: #{response.code}") if (@file_log)
116
+ ruby_body = JSON response.body
117
+ results = ruby_body["results"]
118
+ @log.debug("POST 8 - creating initial sakai docs results: #{results}")
119
+ @file_log.debug("POST 8 - creating initial sakai docs results: #{results}") if (@file_log)
120
+ library_doc_hash, participants_doc_hash = nil, nil
121
+ i = 0
122
+ results.each do |result|
123
+ result_body_json = JSON result["body"]
124
+ content_item = result_body_json["_contentItem"]
125
+ doc_hash = content_item["poolId"]
126
+ content_item_name = content_item["item"]["sakai:pooled-content-file-name"]
127
+ if ("Library".eql? content_item_name)
128
+ library_doc_hash = doc_hash
129
+ elsif ("Participants".eql? content_item_name)
130
+ participants_doc_hash = doc_hash
131
+ else
132
+ @log.warn("could not find sakai doc name to confirm doc_hash")
133
+ end
134
+ end
135
+ @log.info("POST 8 - creating initial sakai docs Library sakai doc hash: #{library_doc_hash}, Participants sakai doc hash #{participants_doc_hash}")
136
+ @file_log.info("POST 8 - creating initial sakai docs Library sakai doc hash: #{library_doc_hash}, Participants sakai doc hash #{participants_doc_hash}") if (@file_log)
137
+
138
+ #POST 9 - importing sakai docs content
139
+ batch_post = []
140
+ batch_post[0] = {"url" => "/p/#{library_doc_hash}.resource", "method" => "POST", "parameters" => {":operation" => "import", ":contentType" => "json", ":replace" => "true", ":replaceProperties" => "true", \
141
+ ":content" => "{\"id9867543247\":{\"page\":\"<img id='widget_mylibrary_id1367865652332' class='widget_inline' style='display: block; padding: 10px; margin: 4px;' \
142
+ src='/devwidgets/mylibrary/images/mylibrary.png' data-mce-src='/devwidgets/mylibrary/images/mylibrary.png' data-mce-style='display: block; padding: 10px; margin: 4px;' border='1'><br></p>\"},\
143
+ \"id1367865652332\":{\"mylibrary\":{\"groupid\":\"#{groupname}\"}}}","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
144
+
145
+ batch_post[1] = {"url" => "/p/#{participants_doc_hash}.resource", "method" => "POST", "parameters" => {":operation" => "import", ":contentType" => "json", ":replace" => "true", ":replaceProperties" => "true", \
146
+ ":content" => "{\"id6573920372\":{\"page\":\"<img id='widget_participants_id439704665' class='widget_inline' style='display: block; padding: 10px; margin: 4px;' src='/devwidgets/participants/images/participants.png' \
147
+ data-mce-src='/devwidgets/participants/images/participants.png' data-mce-style='display: block; padding: 10px; margin: 4px;' border='1'><br></p>\"}, \
148
+ \"id439704665\":{\"participants\":{\"groupid\":\"#{groupname}\"}}}","_charset_" => "utf-8"}, "_charset_" => "utf-8"}
149
+ batch_post_json = JSON.generate batch_post
150
+ @log.debug("POST 9 - importing sakai docs content batch post is: #{batch_post_json}")
151
+ @file_log.debug("POST 9 - importing sakai docs content batch post is: #{batch_post_json}") if (@file_log)
152
+ parameters = {"requests" => batch_post_json}
153
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
154
+ @log.info("POST 9 - importing sakai docs content response code is: #{response.code}")
155
+ @file_log.info("POST 9 - importing sakai docs content response code is: #{response.code}") if (@file_log)
156
+ ruby_body = JSON response.body
157
+ results = ruby_body["results"]
158
+ @log.debug("POST 9 - importing sakai docs content results from importing sakai docs post: #{results}")
159
+ @file_log.debug("POST 9 - importing sakai docs content results from importing sakai docs post: #{results}") if (@file_log)
160
+
161
+ #POST 10 - applying the test tags
162
+ batch_post = []
163
+ batch_post[0] = {"url" => "/~#{groupname}/public/authprofile", "method" => "POST", "parameters" => {"key" => "/tags/test-tag1", ":operation" => "tag", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
164
+ batch_post[1] = {"url" => "/~#{groupname}/public/authprofile", "method" => "POST", "parameters" => {"key" => "/tags/test-tag2", ":operation" => "tag", "_charset_" => "utf-8"}, "_charset_" => "utf-8"}
165
+ @log.debug("resource batch post is: #{batch_post}")
166
+ batch_post_json = JSON.generate batch_post
167
+ @log.debug("POST 10 - applying the test tags batch post is: #{batch_post_json}")
168
+ @file_log.debug("POST 10 - applying the test tags batch post is: #{batch_post_json}") if (@file_log)
169
+ parameters = {"requests" => batch_post_json}
170
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
171
+ @log.info("POST 10 - applying the test tags response code is: #{response.code}")
172
+ @file_log.info("POST 10 - applying the test tags response code is: #{response.code}") if (@file_log)
173
+ ruby_body = JSON response.body
174
+ results = ruby_body["results"]
175
+ @log.debug("POST 10 - applying the test tags results from :operation => tag post: #{results}")
176
+ @file_log.debug("POST 10 - applying the test tags results from :operation => tag post: #{results}") if (@file_log)
177
+
178
+
179
+ #POST 11 - setting the global viewers and permissions on the sakai docs
180
+ batch_post = []
181
+ batch_post[0] = {"url" => "/p/#{library_doc_hash}.members.html", "method" => "POST", "parameters" => {":viewer" => ["everyone", "anonymous"]}}
182
+ batch_post[1] = {"url" => "/p/#{library_doc_hash}.modifyAce.html", "method" => "POST", "parameters" => {"principalId" => ["everyone", "anonymous"], "privilege@jcr:read" => "granted"}}
183
+ batch_post[2] = {"url" => "/p/#{participants_doc_hash}.members.html", "method" => "POST", "parameters" => {":viewer" => ["everyone", "anonymous"]}}
184
+ batch_post[3] = {"url" => "/p/#{participants_doc_hash}.modifyAce.html", "method" => "POST", "parameters" => {"principalId" => ["everyone", "anonymous"], "privilege@jcr:read" => "granted"}}
185
+ batch_post_json = JSON.generate batch_post
186
+ @log.debug("POST 11 - setting the global viewers and permissions on the sakai docs batch post is: #{batch_post_json}")
187
+ @file_log.debug("POST 11 - setting the global viewers and permissions on the sakai docs batch post is: #{batch_post_json}") if (@file_log)
188
+ parameters = {"requests" => batch_post_json}
189
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
190
+ @log.info("POST 11 - setting the global viewers and permissions on the sakai docs response code is: #{response.code}")
191
+ @file_log.info("POST 11 - setting the global viewers and permissions on the sakai docs response code is: #{response.code}") if (@file_log)
192
+ ruby_body = JSON response.body
193
+ results = ruby_body["results"]
194
+ @log.debug("POST 11 - setting the global viewers and permissions on the sakai docs results from setting permissions on sakai docs #{results}")
195
+ @file_log.debug("POST 11 - setting the global viewers and permissions on the sakai docs results from setting permissions on sakai docs #{results}") if (@file_log)
196
+
197
+ #POST 12 - setting the member viewer and manager viewer for the sakai docs
198
+ batch_post = []
199
+ batch_post[0] = {"url" => "/p/#{library_doc_hash}.members.html", "method" => "POST", "parameters" => {":viewer" => "#{groupname}-member", "_charset_" =>"utf-8"},"_charset_" => "utf-8"}
200
+ batch_post[1] = {"url" => "/p/#{library_doc_hash}.members.html", "method" => "POST", "parameters" => {":manager" => "#{groupname}-manager", "_charset_" =>"utf-8"},"_charset_" => "utf-8"}
201
+ batch_post[2] = {"url" => "/p/#{participants_doc_hash}.members.html", "method" => "POST", "parameters" => {":viewer" => "#{groupname}-member", "_charset_" =>"utf-8"},"_charset_" => "utf-8"}
202
+ batch_post[3] = {"url" => "/p/#{participants_doc_hash}.members.html", "method" => "POST", "parameters" => {":manager" => "#{groupname}-manager", "_charset_" =>"utf-8"},"_charset_" => "utf-8"}
203
+ batch_post_json = JSON.generate batch_post
204
+ @log.debug("POST 12 - setting the member viewer and manager viewer for the sakai docs batch post is: #{batch_post_json}")
205
+ @file_log.debug("POST 12 - setting the member viewer and manager viewer for the sakai docs batch post is: #{batch_post_json}") if (@file_log)
206
+ parameters = {"requests" => batch_post_json}
207
+ response = @sling.execute_post(@sling.url_for("#{$BATCH_URI}"), parameters)
208
+ @log.info("POST 12 - setting the member viewer and manager viewer for the sakai docs response code is: #{response.code}")
209
+ @file_log.info("POST 12 - setting the member viewer and manager viewer for the sakai docs response code is: #{response.code}") if (@file_log)
210
+ ruby_body = JSON response.body
211
+ results = response.body["results"]
212
+ @log.debug("POST 12 - setting the member viewer and manager viewer for the sakai docs results from setting viewer and manager on sakai docs #{results}")
213
+ @file_log.debug("POST 12 - setting the member viewer and manager viewer for the sakai docs results from setting viewer and manager on sakai docs #{results}") if (@file_log)
214
+
215
+ #POST 13 - setting the doc structure on the sakai docs
216
+ struct0 = {}
217
+ str = "{\"library\":{\"_title\":\"Library\",\"_order\":0,\"_nonEditable\":true,\"_view\":\"[\\\"everyone\\\",\\\"anonymous\\\",\\\"-member\\\"]\",\"_edit\":\"[\\\"-manager\\\"]\",\"_pid\":\"#{library_doc_hash}\"},\"participants\":{\"_title\":\"Participants\",\"_order\":1,\"_nonEditable\":true,\"_view\":\"[\\\"everyone\\\",\\\"anonymous\\\",\\\"-member\\\"]\",\"_edit\":\"[\\\"-manager\\\"]\",\"_pid\":\"#{participants_doc_hash}\"}}"
218
+ struct0["structure0"] = str
219
+ params = {}
220
+ params[":content"] = JSON.generate struct0
221
+ params[":contentType"] = "json"
222
+ params[":operation"] = "import"
223
+ params[":replace"] = true
224
+ params[":replaceProperties"] = true
225
+ params["_charset_"] = "utf-8"
226
+ @log.debug("POST 13 - setting the doc structure on the sakai docs post params are: " + params.inspect)
227
+ @file_log.debug("POST 13 - setting the doc structure on the sakai docs post params are: " + params.inspect) if (@file_log)
228
+ uri = "/~#{groupname}/docstructure"
229
+ response = @sling.execute_post(@sling.url_for(uri), params)
230
+ #this is an html response
231
+ @log.info("POST 13 - setting the doc structure on the sakai docs response code: #{response.code}")
232
+ @file_log.info("POST 13 - setting the doc structure on the sakai docs response code: #{response.code}") if (@file_log)
233
+
234
+ # return the group that was created in create_target_group
235
+ return group
236
+ end
237
+
238
+ # create the manager and member pseudo subgroups
239
+ def create_pseudo_group(groupname, title, description)
240
+ params = { ":name" => groupname }
241
+ params["sakai:pseudoGroup"] = true
242
+ params["sakai:excludeSearch"] = true
243
+ params["sakai:group-description"] = description || ""
244
+ params["sakai:group-id"] = groupname
245
+ params["sakai:group-title"] = title
246
+ response = @sling.execute_post(@sling.url_for($GROUP_URI), params)
247
+ @log.info("create_pseudo_group() for #{groupname} POST response code: #{response.code}")
248
+ @log.debug("create_pseudo_group() for #{groupname} POST response body: #{response.body}")
249
+ @file_log.info("create_pseudo_group() for #{groupname} POST response code: #{response.code}") if (@file_log)
250
+ @file_log.debug("create_pseudo_group() for #{groupname} POST response body: #{response.body}") if (@file_log)
251
+ if (response.code.to_i > 299)
252
+ @log.warn("create_pseudo_group() returned #{response.code} group may already exist?")
253
+ @file_log.warn("create_pseudo_group() returned #{response.code} group may already exist?") if (@file_log)
254
+ end
255
+ end
256
+
257
+ # create the group itself
258
+ def create_target_group(groupname, title, description)
259
+ params = { ":name" => groupname }
260
+ params["sakai:category"] = "group"
261
+ params["sakai:group-description"] = description || ""
262
+ params["sakai:group-id"] = groupname
263
+ params["sakai:group-title"] = title || ""
264
+ params["sakai:joinRole"] = "member"
265
+ params["sakai:roles"] = '[{"id":"member","title":"Member","allowManage":false},{"id":"manager","title":"Manager","allowManage":true}]'
266
+ params["sakai:templateid"] = "simplegroup"
267
+ response = @sling.execute_post(@sling.url_for($GROUP_URI), params)
268
+ @log.info("create_target_group() for #{groupname} POST response code: #{response.code}")
269
+ @log.debug("create_target_group() for #{groupname} POST response body: #{response.body}")
270
+ @file_log.info("create_target_group() for #{groupname} POST response code: #{response.code}") if (@file_log)
271
+ @file_log.debug("create_target_group() for #{groupname} POST response body: #{response.body}") if (@file_log)
272
+ if (response.code.to_i > 299)
273
+ @log.warn("create_target_group() returned #{response.code} group may already exist?")
274
+ @file_log.warn("create_target_group() returned #{response.code} group may already exist?") if (@file_log)
275
+ end
276
+ group = Group.new(groupname)
277
+ return group
278
+ end
279
+
280
+ end
281
+
282
+ if ($PROGRAM_NAME.include? 'full_group_creator.rb')
283
+ @sling = Sling.new("http://localhost:8080/", false)
284
+ @sling.log.level = Logger::DEBUG
285
+ fgc = SlingUsers::FullGroupCreator.new @sling
286
+ fgc.log.level = Logger::DEBUG
287
+ fgc.file_log.level = Logger::DEBUG if (@file_log)
288
+ fgc.create_full_group "bp7742", "test-1881-group8", "test-1881-group8 Title", "test-1881-group8 Description"
289
+ end
290
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'digest/sha1'
4
+
5
+ module SlingMessage
6
+
7
+ class MessageManager
8
+
9
+ def initialize(sling)
10
+ @sling = sling
11
+ end
12
+
13
+ def create(name, type, box = "drafts", props = {})
14
+ @home = @sling.get_user().home_path_for(@sling)
15
+ return @sling.execute_post(@sling.url_for("#{@home}/message.create.html"), props.update("sakai:type" => type, "sakai:to" => name, "sakai:sendstate" => "pending", "sakai:messagebox" => box))
16
+ end
17
+
18
+ def send(messageId, sender)
19
+ # this is the old sharded version of the message path
20
+ # path = "" + messageId[0, 2] + "/" + messageId[2, 2] + "/" + messageId[4,2]+ "/" + messageId[6,2] + "/" + messageId
21
+ # postUrl = @sling.url_for("#{@home}/message/#{path}.html")
22
+ path = messageId
23
+ postUrl = @sling.url_for("~#{sender}/message/outbox/#{path}.html")
24
+ return @sling.execute_post(postUrl, "sakai:messagebox" => "outbox" )
25
+ end
26
+
27
+ def list_all_noopts()
28
+ return @sling.execute_get(@sling.url_for("system/messages.json?box=all"))
29
+ end
30
+
31
+ def list_all(sortOn = "jcr:created", sortOrder = "descending" )
32
+ return @sling.execute_get(@sling.url_for("system/messages.json?box=all&sortOn="+sortOn+"&sortOrder="+sortOrder))
33
+ end
34
+
35
+ def list_inbox(sortOn = "jcr:created", sortOrder = "descending" )
36
+ return @sling.execute_get(@sling.url_for("system/messages.json?box=inbox&sortOn="+sortOn+"&sortOrder="+sortOrder))
37
+ end
38
+
39
+ def list_outbox(sortOn = "jcr:created", sortOrder = "descending" )
40
+ return @sling.execute_get(@sling.url_for("system/messages.json?box=outbox&sortOn="+sortOn+"&sortOrder="+sortOrder))
41
+ end
42
+
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module SlingSearch
4
+
5
+ $SEARCH = "var/search/"
6
+
7
+ class SearchManager
8
+
9
+ def initialize(sling)
10
+ @sling = sling
11
+ end
12
+
13
+ def search_for(string)
14
+ return json_search("content", "q" => string)
15
+ end
16
+
17
+ def create_search_template(name, language, template)
18
+ return @sling.create_node("#{$SEARCH}#{name}", "sakai:query-language" => language, "sakai:query-template" => template, "sling:resourceType" => "sakai/search")
19
+ end
20
+
21
+ def search_for_user(username)
22
+ return json_search("users", "q" => username)
23
+ end
24
+
25
+ def search_for_group(group)
26
+ return json_search("groups", "q" => group)
27
+ end
28
+
29
+ def search_for_site(sitepropertyvalue)
30
+ return json_search("sites", "q" => sitepropertyvalue)
31
+ end
32
+
33
+ private
34
+ def json_search(template, params)
35
+ return JSON.parse(@sling.execute_get(@sling.url_for($SEARCH + template) + ".json?" + params.collect{|k,v| URI.escape(k) + "=" + URI.escape(v)}.join("&")).body)
36
+ end
37
+ end
38
+
39
+ end