activesp 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ module ActiveSP
2
+
3
+ class User < Base
4
+
5
+ extend Caching
6
+ extend PersistentCaching
7
+ include Util
8
+ include InSite
9
+
10
+ attr_reader :login_name
11
+
12
+ persistent { |site, login_name, *a| [site.connection, [:user, login_name]] }
13
+ def initialize(site, login_name)
14
+ @site, @login_name = site, login_name
15
+ end
16
+
17
+ def key
18
+ encode_key("U", [@login_name])
19
+ end
20
+
21
+ def to_s
22
+ "#<ActiveSP::User login_name=#{login_name}>"
23
+ end
24
+
25
+ alias inspect to_s
26
+
27
+ private
28
+
29
+ def data
30
+ call("UserGroup", "get_user_info", "userLoginName" => @login_name).xpath("//spdir:User", NS).first
31
+ end
32
+ cache :data
33
+
34
+ def attributes_before_type_cast
35
+ clean_attributes(data.attributes)
36
+ end
37
+ cache :attributes_before_type_cast
38
+
39
+ def original_attributes
40
+ type_cast_attributes(@site, nil, internal_attribute_types, attributes_before_type_cast)
41
+ end
42
+ cache :original_attributes
43
+
44
+ def internal_attribute_types
45
+ @@internal_attribute_types ||= {
46
+ "Email" => GhostField.new("Email", "Text", false, true),
47
+ "ID" => GhostField.new("ID", "Text", false, true),
48
+ "IsDomainGroup" => GhostField.new("Email", "Bool", false, true),
49
+ "IsSiteAdmin" => GhostField.new("IsSiteAdmin", "Bool", false, true),
50
+ "LoginName" => GhostField.new("LoginName", "Text", false, true),
51
+ "Name" => GhostField.new("Name", "Text", false, true),
52
+ "Notes" => GhostField.new("Notes", "Text", false, true),
53
+ "Sid" => GhostField.new("Sid", "Text", false, true)
54
+ }
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,168 @@
1
+ module ActiveSP
2
+
3
+ module Util
4
+
5
+ private
6
+
7
+ def clean_attributes(attributes)
8
+ attributes.inject({}) { |h, (k, v)| h[k] = v.to_s ; h }
9
+ end
10
+
11
+ def clean_item_attributes(attributes)
12
+ attributes.inject({}) { |h, (k, v)| h[k.sub(/\Aows_/, "")] = v.to_s ; h }
13
+ end
14
+
15
+ def type_cast_attributes(site, list, fields, attributes)
16
+ attributes.inject({}) do |h, (k, v)|
17
+ if field = fields[k]
18
+ case field.internal_type
19
+ when "ListReference"
20
+ when "StandardDateTime"
21
+ v = Time.parse(v)
22
+ when "DateTime"
23
+ v = Time.parse(v)
24
+ when "XMLDateTime"
25
+ v = Time.xmlschema(v.sub(/ /, "T"))
26
+ when "Computed", "Text", "Guid", "ContentTypeId", "URL"
27
+ when "Integer", "Counter", "Attachments"
28
+ v = v && v != "" ? Integer(v) : nil
29
+ when "ModStat" # 0
30
+ when "Number"
31
+ v = v.to_f
32
+ when "Boolean"
33
+ v = v == "1"
34
+ when "Bool"
35
+ v = !!v[/true/i]
36
+ when "File"
37
+ # v = v.sub(/\A.*?;#/, "")
38
+ when "Note"
39
+
40
+ when "User"
41
+ d = split_multi(v)
42
+ v = User.new(site.connection.root, d[2][/\\/] ? d[2] : "SHAREPOINT\\system")
43
+ when "InternalUser"
44
+ v = User.new(site.connection.root, v[/\\/] ? v : "SHAREPOINT\\system")
45
+ when "UserMulti"
46
+ d = split_multi(v)
47
+ v = (0...(d.length / 4)).map { |i| User.new(site.connection.root, d[4 * i + 2][/\\/] ? d[4 * i + 2] : "SHAREPOINT\\system") }
48
+
49
+ when "Choice"
50
+ # For some reason there is no encoding here
51
+ when "MultiChoice"
52
+ # SharePoint disallows ;# inside choices and starts with a ;#
53
+ v = v.split(/;#/)[1..-1]
54
+
55
+ when "Lookup"
56
+ d = split_multi(v)
57
+ if field.List
58
+ v = create_item_from_id(field.List, d[0])
59
+ else
60
+ v = d[2]
61
+ end
62
+ when "LookupMulti"
63
+ d = split_multi(v)
64
+ if field.List
65
+ v = (0...(d.length / 4)).map { |i| create_item_from_id(field.List, d[4 * i]) }
66
+ else
67
+ v = (0...(d.length / 4)).map { |i| d[4 * i + 2] }
68
+ end
69
+
70
+ else
71
+ # raise NotImplementedError, "don't know type #{field.type.inspect} for #{k}=#{v.inspect}"
72
+ warn "don't know type #{field.internal_type.inspect} for #{k}=#{v.inspect} on self"
73
+ end
74
+ else
75
+ # raise ArgumentError, "can't find field #{k.inspect}"
76
+ warn "can't find field #{k.inspect} on #{self}"
77
+ end
78
+ h[k] = v
79
+ h
80
+ end
81
+ end
82
+
83
+ def encode_key(type, trail)
84
+ "#{type}::#{trail.map { |t| t.to_s.gsub(/:/, ":-") }.join("::")}"
85
+ end
86
+
87
+ def decode_key(key)
88
+ type, *trail = key.split(/::/)
89
+ [type, trail.map { |t| t.gsub(/:-/, ':') }]
90
+ end
91
+
92
+ def split_multi(s)
93
+ # Figure out the exact escaping rules that SharePoint uses
94
+ s.scan(/((?:[^;]|;;#|;[^#;]|;;(?!#))+)(;#)?/).flatten
95
+ end
96
+
97
+ def create_item_from_id(list, id)
98
+ query = Builder::XmlMarkup.new.Query do |xml|
99
+ xml.Where do |xml|
100
+ xml.Eq do |xml|
101
+ xml.FieldRef(:Name => "ID")
102
+ xml.Value(id, :Type => "Counter")
103
+ end
104
+ end
105
+ end
106
+ list.items(:query => query).first
107
+ end
108
+
109
+ def translate_internal_type(field)
110
+ case field.internal_type
111
+ when "Computed", "Text", "Guid", "ContentTypeId", "URL", "Choice", "MultiChoice", "File", "Note"
112
+ "Text"
113
+ when "Integer", "Counter", "Attachments", "ModStat"
114
+ "Integer"
115
+ when "Number"
116
+ "Float"
117
+ when "StandardDateTime", "DateTime", "XMLDateTime"
118
+ "DateTime"
119
+ when "Boolean", "Bool"
120
+ "Boolean"
121
+ when "User", "InternalUser", "UserMulti"
122
+ "UserReference"
123
+ when "Lookup", "LookupMulti"
124
+ if field.List
125
+ "ItemReference"
126
+ else
127
+ "Text"
128
+ end
129
+ when "ListReference"
130
+ "ListReference"
131
+ else
132
+ "Text"
133
+ end
134
+ end
135
+
136
+ end
137
+
138
+ end
139
+
140
+
141
+ __END__
142
+
143
+ escaping in field names:
144
+
145
+ _x[4-digit code]_
146
+
147
+ [space] 20
148
+ < 3C
149
+ > 3E
150
+ # 23
151
+ % 25
152
+ { 7B
153
+ } 7D
154
+ | 7C
155
+ \ 5C
156
+ ^ 5E
157
+ ~ 7E
158
+ [ 5B
159
+ ] 5D
160
+ ` 60
161
+ ; 3B
162
+ / 2F
163
+ ? 3F
164
+ : 3A
165
+ @ 40
166
+ = 3D
167
+ & 26
168
+ $ 24
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activesp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Vanbroekhoven
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-04-02 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: savon-xaop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Interface to SharePoint
36
+ email: peter@xaop.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - VERSION
45
+ - Rakefile
46
+ - lib/activesp/base.rb
47
+ - lib/activesp/caching.rb
48
+ - lib/activesp/connection.rb
49
+ - lib/activesp/content_type.rb
50
+ - lib/activesp/field.rb
51
+ - lib/activesp/folder.rb
52
+ - lib/activesp/ghost_field.rb
53
+ - lib/activesp/group.rb
54
+ - lib/activesp/item.rb
55
+ - lib/activesp/list.rb
56
+ - lib/activesp/permission_set.rb
57
+ - lib/activesp/persistent_caching.rb
58
+ - lib/activesp/role.rb
59
+ - lib/activesp/root.rb
60
+ - lib/activesp/site.rb
61
+ - lib/activesp/url.rb
62
+ - lib/activesp/user.rb
63
+ - lib/activesp/util.rb
64
+ - lib/activesp.rb
65
+ has_rdoc: true
66
+ homepage:
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.8.1
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project:
90
+ rubygems_version: 1.3.5
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Interface to SharePoint
94
+ test_files: []
95
+