Browse Source

added both types of typeIndexes

deiu 5 years ago
parent
commit
56bc9f9a31
4 changed files with 55 additions and 44 deletions
  1. 10 8
      acl_test.go
  2. 14 10
      system.go
  3. 30 25
      webid.go
  4. 1 1
      webid_test.go

+ 10 - 8
acl_test.go

@@ -20,10 +20,11 @@ func TestACLInit(t *testing.T) {
 
 	user1 = testServer.URL + "/_test/user1#id"
 	var user1_account = webidAccount{
-		WebID:     user1,
-		BaseURI:   testServer.URL + "/_test/",
-		PrefURI:   testServer.URL + "/_test/Preferences/prefs.ttl",
-		TypeIndex: testServer.URL + "/_test/Preferences/typeIndex.ttl",
+		WebID:         user1,
+		BaseURI:       testServer.URL + "/_test/",
+		PrefURI:       testServer.URL + "/_test/Preferences/prefs.ttl",
+		PubTypeIndex:  testServer.URL + "/_test/Preferences/pubTypeIndex.ttl",
+		PrivTypeIndex: testServer.URL + "/_test/Preferences/privTypeIndex.ttl",
 	}
 	user1g := NewWebIDProfile(user1_account)
 	user1g, user1k, user1p, err = AddProfileKeys(user1, user1g)
@@ -48,10 +49,11 @@ func TestACLInit(t *testing.T) {
 
 	user2 = testServer.URL + "/_test/user2#id"
 	var user2_account = webidAccount{
-		WebID:     user2,
-		BaseURI:   testServer.URL + "/_test/",
-		PrefURI:   testServer.URL + "/_test/Preferences/prefs.ttl",
-		TypeIndex: testServer.URL + "/_test/Preferences/typeIndex.ttl",
+		WebID:         user2,
+		BaseURI:       testServer.URL + "/_test/",
+		PrefURI:       testServer.URL + "/_test/Preferences/prefs.ttl",
+		PubTypeIndex:  testServer.URL + "/_test/Preferences/pubTypeIndex.ttl",
+		PrivTypeIndex: testServer.URL + "/_test/Preferences/privTypeIndex.ttl",
 	}
 	user2g := NewWebIDProfile(user2_account)
 	user2g, user2k, user2p, err = AddProfileKeys(user2, user2g)

+ 14 - 10
system.go

@@ -81,6 +81,8 @@ func passwordAuth(w http.ResponseWriter, req *httpRequest, s *Server) SystemRetu
 	redirTo := req.FormValue("redirect")
 	origin := req.FormValue("origin")
 
+	s.debug.Println("Got login request. Optional params: ", redirTo, origin)
+
 	// if cookie is set, just redirect
 	if len(req.User) > 0 {
 		values := map[string]string{
@@ -170,6 +172,7 @@ func loginRedirect(w http.ResponseWriter, req *httpRequest, s *Server, values ma
 	}
 	s.debug.Println("Generated new token for", values["webid"], "->", key)
 	redirTo += "?webid=" + encodeQuery(values["webid"]) + "&key=" + encodeQuery(key)
+	s.debug.Println("Redirecting user to", redirTo)
 	http.Redirect(w, req.Request, redirTo, 301)
 	return SystemReturn{Status: 200}
 }
@@ -340,16 +343,17 @@ func newAccount(w http.ResponseWriter, req *httpRequest, s *Server) SystemReturn
 	resource, _ = req.pathInfo(accountBase)
 
 	account := webidAccount{
-		Root:      resource.Root,
-		BaseURI:   resource.Base,
-		Document:  resource.File,
-		WebID:     webidURI,
-		Agent:     s.Config.Agent,
-		PrefURI:   accountBase + "Preferences/prefs.ttl",
-		TypeIndex: accountBase + "Preferences/typeIndex.ttl",
-		Email:     req.FormValue("email"),
-		Name:      req.FormValue("name"),
-		Img:       req.FormValue("img"),
+		Root:          resource.Root,
+		BaseURI:       resource.Base,
+		Document:      resource.File,
+		WebID:         webidURI,
+		Agent:         s.Config.Agent,
+		PrefURI:       accountBase + "Preferences/prefs.ttl",
+		PubTypeIndex:  accountBase + "Preferences/pubTypeIndex.ttl",
+		PrivTypeIndex: accountBase + "Preferences/privTypeIndex.ttl",
+		Email:         req.FormValue("email"),
+		Name:          req.FormValue("name"),
+		Img:           req.FormValue("img"),
 	}
 	if len(s.Config.ProxyTemplate) > 0 {
 		account.ProxyURI = accountBase + ",proxy?uri="

+ 30 - 25
webid.go

@@ -23,18 +23,19 @@ const (
 )
 
 type webidAccount struct {
-	Root      string
-	BaseURI   string
-	Document  string
-	WebID     string
-	PrefURI   string
-	TypeIndex string
-	Name      string
-	Email     string
-	Agent     string
-	ProxyURI  string
-	QueryURI  string
-	Img       string
+	Root          string
+	BaseURI       string
+	Document      string
+	WebID         string
+	PrefURI       string
+	PubTypeIndex  string
+	PrivTypeIndex string
+	Name          string
+	Email         string
+	Agent         string
+	ProxyURI      string
+	QueryURI      string
+	Img           string
 }
 
 type workspace struct {
@@ -371,7 +372,8 @@ func NewWebIDProfile(account webidAccount) *Graph {
 	}
 	g.AddTriple(userTerm, ns.space.Get("storage"), NewResource(account.BaseURI+"/"))
 	g.AddTriple(userTerm, ns.space.Get("preferencesFile"), NewResource(account.PrefURI))
-	g.AddTriple(userTerm, ns.st.Get("privateTypeIndex"), NewResource(account.TypeIndex))
+	g.AddTriple(userTerm, ns.st.Get("privateTypeIndex"), NewResource(account.PrivTypeIndex))
+	g.AddTriple(userTerm, ns.st.Get("publicTypeIndex"), NewResource(account.PubTypeIndex))
 	g.AddTriple(userTerm, ns.st.Get("inbox"), NewResource(account.BaseURI+"/Inbox/"))
 	g.AddTriple(userTerm, ns.st.Get("timeline"), NewResource(account.BaseURI+"/Timeline/"))
 
@@ -502,27 +504,30 @@ func (req *httpRequest) AddWorkspaces(account webidAccount, g *Graph) error {
 	f.Close()
 
 	// write the typeIndex
-	typeIndex := NewGraph(account.TypeIndex)
-	typeIndex.AddTriple(NewResource(account.TypeIndex), ns.rdf.Get("type"), ns.st.Get("TypeIndex"))
-	typeIndex.AddTriple(NewResource(account.TypeIndex), ns.rdf.Get("type"), ns.st.Get("UnlistedDocument"))
+	createTypeIndex(req, "ListedDocument", account.PubTypeIndex)
+	createTypeIndex(req, "UnlistedDocument", account.PrivTypeIndex)
 
-	resource, _ = req.pathInfo(account.TypeIndex)
-	err = os.MkdirAll(_path.Dir(resource.File), 0755)
+	return nil
+}
+
+func createTypeIndex(req *httpRequest, indexType, url string) error {
+	typeIndex := NewGraph(url)
+	typeIndex.AddTriple(NewResource(url), ns.rdf.Get("type"), ns.st.Get("TypeIndex"))
+	typeIndex.AddTriple(NewResource(url), ns.rdf.Get("type"), ns.st.Get(indexType))
+
+	resource, _ := req.pathInfo(url)
+	err := os.MkdirAll(_path.Dir(resource.File), 0755)
 	if err != nil {
 		return err
 	}
 	// open account acl file
-	f, err = os.OpenFile(resource.File, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
+	f, err := os.OpenFile(resource.File, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)
 	if err != nil {
 		return err
 	}
+	defer f.Close()
 
 	// write account acl to disk
 	err = typeIndex.WriteFile(f, "text/turtle")
-	if err != nil {
-		return err
-	}
-	f.Close()
-
-	return nil
+	return err
 }

+ 1 - 1
webid_test.go

@@ -28,5 +28,5 @@ func TestAddProfileKeys(t *testing.T) {
 	assert.NoError(t, err)
 	assert.NotNil(t, k)
 	assert.NotNil(t, p)
-	assert.Equal(t, 14, g.Len())
+	assert.Equal(t, 15, g.Len())
 }