Changeset 1448

Show
Ignore:
Timestamp:
07/01/07 00:34:06
Author:
douglm
Message:

Setting access for an event in user client almost works again

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/deployment/webuser/webapp/resources/demoskins/resources/bedeworkAccess.js

    r1446 r1448  
    4444// ======================================================================== 
    4545//   Language and customization 
     46//   These should come from values in the header or included as a separate cutomization 
     47//   file. 
    4648 
    4749var authenticatedStr = "authenticated"; 
     
    5254var grantStr = "grant"; 
    5355 
     56// How granted accesses appear 
    5457var howAllVal = "all"; 
    5558 
     
    7477var howUnlockVal = "unlock"; 
    7578 
    76 var howNoneVal = "none"; 
     79// How denied accesses appear 
     80var howDenyAllVal = "none"; 
     81 
     82var howDenyReadVal = "not-read"; 
     83var howDenyReadAclVal = "not-read-acl"; 
     84var howDenyReadCurPrivSetVal = "not-read-curprivset"; 
     85var howDenyReadFreebusyVal = "not-read-freebusy "; 
     86 
     87var howDenyWriteVal = "not-write"; 
     88var howDenyWriteAclVal = "not-write-acl"; 
     89var howDenyWritePropertiesVal = "not-write-properties"; 
     90var howDenyWriteContentVal = "not-write-content"; 
     91 
     92var howDenyBindVal = "not-create"; 
     93var howDenyScheduleVal = "not-schedule"; 
     94var howDenyScheduleRequestVal = "not-schedule-request"; 
     95var howDenyScheduleReplyVal = "not-schedule-reply"; 
     96var howDenyScheduleFreebusyVal = "not-schedule-freebusy"; 
     97 
     98var howDenyUnbindVal = "not-delete"; 
     99 
     100var howDenyUnlockVal = "not-unlock"; 
     101 
     102//var howNoneVal = "none"; 
     103 
     104/* We shouldn't use the word local - it probably doesn't mean too much and it might actually be 
     105   inherited from something called /local for example */ 
     106var inheritedStr = "Not inherited"; 
     107 
     108// ************************** 
     109// The prefixes come from the directory code so should be emitted by the jsp. 
     110// We may have problems here as convertng from a user id to a principal might be 
     111// awkward 
     112 
     113var principalPrefix = "/principals/"; 
     114var userPrincipalPrefix = "/principals/users/"; 
     115var groupPrincipalPrefix = "/principals/groups/"; 
     116var resourcePrincipalPrefix = "/principals/resources/"; 
    77117 
    78118// ======================================================================== 
    79119// ======================================================================== 
    80120 
    81 /* Define how values, first par is the how, 
    82    second the contained hows 
    83    third the display name */ 
    84 function howVals(h, cont, dv) { 
     121// ....................................................... 
     122// Some constants 
     123// ....................................................... 
     124 
     125var xmlHeader = "<?xml version='1.0' encoding='utf-8'  ?>"; 
     126var nameSpaces = "xmlns:D='DAV:' " + 
     127                 "xmlns:C='urn:ietf:params:xml:ns:caldav'"; 
     128 
     129var davNS = "D:"; 
     130var caldavNS = "C:"; 
     131 
     132/* Define how values, 
     133    par: how, 
     134    par: the contained hows 
     135    par: dav element name 
     136    par: display name */ 
     137function howVals(h, cont, davEl, dv, ddv) { 
    85138  var how; 
    86139  var contains; 
     140  var davEl; 
    87141  var dispVal; 
     142  var denyDispVal; 
    88143 
    89144  this.how = h; 
    90145  this.contains = cont; 
     146  this.davEl = davEl; 
    91147  this.dispVal = dv; 
     148  this.denyDispVal = ddv; 
    92149 
    93150  /* return true if ch is contained in this access */ 
     
    95152    return this.contains.match(ch) != null; 
    96153  } 
     154 
     155  this.getDispVal = function(negated) { 
     156    if (negated) { 
     157      return this.denyDispVal; 
     158    } 
     159 
     160    return this.dispVal; 
     161  } 
    97162} 
    98163 
     
    100165  var hv = new Array(); 
    101166 
    102   hv.push(new howVals("A", "RrPFWapcbStysuN", howAllVal)); 
    103  
    104   hv.push(new howVals("R", "rPF", howReadVal)); 
    105   hv.push(new howVals("r", "", howReadAclVal)); 
    106   hv.push(new howVals("P", "", howReadCurPrivSetVal)); 
    107   hv.push(new howVals("F", "", howReadFreebusyVal)); 
    108  
    109   hv.push(new howVals("W", "apcbStysuN", howWriteVal)); 
    110   hv.push(new howVals("a", "", howWriteAclVal)); 
    111   hv.push(new howVals("p", "", howWritePropertiesVal)); 
    112   hv.push(new howVals("c", "", howWriteContentVal)); 
    113  
    114   hv.push(new howVals("b", "Stys", howBindVal)); 
    115   hv.push(new howVals("S", "tys", howScheduleVal)); 
    116   hv.push(new howVals("t", "", howScheduleRequestVal)); 
    117   hv.push(new howVals("y", "", howScheduleReplyVal)); 
    118   hv.push(new howVals("s", "", howScheduleFreebusyVal)); 
    119  
    120   hv.push(new howVals("u", "", howUnbindVal)); 
    121  
    122   hv.push(new howVals("U", "", howUnlockVal)); 
    123  
    124   hv.push(new howVals("N", "rPFapcbStysu", howNoneVal)); 
     167  hv.push(new howVals("A", "RrPFWapcbStysuN", "<D:all/>", howAllVal, howDenyAllVal)); 
     168 
     169  hv.push(new howVals("R", "rPF", "<D:read/>", howReadVal, howDenyReadVal)); 
     170  hv.push(new howVals("r", "", "<D:read-acl/>", howReadAclVal, howDenyReadAclVal)); 
     171  hv.push(new howVals("P", "", "<D:read-current-user-privilege-set/>", howReadCurPrivSetVal, howDenyReadCurPrivSetVal)); 
     172  hv.push(new howVals("F", "", "<C:read-free-busy/>", howReadFreebusyVal, howDenyReadFreebusyVal)); 
     173 
     174  hv.push(new howVals("W", "apcbStysuN", "<D:write/>", howWriteVal, howDenyWriteVal)); 
     175  hv.push(new howVals("a", "", "<D:write-acl/>", howWriteAclVal, howDenyWriteAclVal)); 
     176  hv.push(new howVals("p", "", "<D: write-properties/>", howWritePropertiesVal, howDenyWritePropertiesVal)); 
     177  hv.push(new howVals("c", "", "<D:write-content/>", howWriteContentVal, howDenyWriteContentVal)); 
     178 
     179  hv.push(new howVals("b", "Stys", "<D:bind/>", howBindVal, howDenyBindVal)); 
     180  hv.push(new howVals("S", "tys", "<C:schedule/>", howScheduleVal, howDenyScheduleVal)); 
     181  hv.push(new howVals("t", "", "<C:schedule-request/>", howScheduleRequestVal, howDenyScheduleRequestVal)); 
     182  hv.push(new howVals("y", "", "<C:schedule-reply/>", howScheduleReplyVal, howDenyScheduleReplyVal)); 
     183  hv.push(new howVals("s", "", "<C:schedule-free-busy/>", howScheduleFreebusyVal, howDenyScheduleFreebusyVal)); 
     184 
     185  hv.push(new howVals("u", "", "<D:unbind/>", howUnbindVal, howDenyUnbindVal)); 
     186 
     187  hv.push(new howVals("U", "", "<D:unlock/>", howUnlockVal, howDenyUnlockVal)); 
     188 
     189  //hv.push(new howVals("N", "rPFapcbStysu", "", howNoneVal)); // None is -A 
    125190 
    126191  this. getHows = function(ch) { 
     
    130195      } 
    131196    } 
     197 
     198    alert("No how values for how=" + ch); 
    132199 
    133200    return null; 
     
    180247  } 
    181248} 
     249 
    182250// Gather up the how values on access form submission and set the how field 
    183251// (method 1) or return the value (method 2). 
     
    219287} 
    220288 
    221  
    222 /* METHOD TWO FUNCTIONS*/ 
    223 // Acces Control Entry (ACE) object 
    224  
    225  
    226 function bwAce(who,whoType,how,inherited,invert) { 
     289/* Information about a principal 
     290 */ 
     291function bwPrincipal(who, whoType) { 
    227292  this.who = who; 
    228293  this.whoType = whoType; 
     294 
     295  // Don't touch email like addresses 
     296  if (who.indexOf("@") < 0) { 
     297    // Normalize the who 
     298    if (whoType == "user") { 
     299      if (who.indexOf(principalPrefix) != "0") { 
     300        who = userPrincipalPrefix + who; 
     301      } 
     302    } else if (whoType == "group") { 
     303      if (who.indexOf(principalPrefix) != "0") { 
     304        who = groupPrincipalPrefix + who; 
     305      } 
     306    } else if (whoType == "resource") { 
     307      if (who.indexOf(principalPrefix) != "0") { 
     308        who = resourcePrincipalPrefix + who; 
     309      } 
     310    } 
     311  } 
     312 
     313  // format the who string for on-screen display 
     314  this.format = function() { 
     315    if (whoType == "user") { 
     316      return who; 
     317    } 
     318 
     319    if (whoType == "group") { 
     320      return who; 
     321    } 
     322 
     323    if (whoType == "resource") { 
     324      return who; 
     325    } 
     326 
     327    if (whoType == "auth") { 
     328      return authenticatedStr; 
     329    } 
     330 
     331    if (whoType == "unauth") { 
     332      return unauthenticatedStr; 
     333    } 
     334 
     335    if (whoType == "owner") { 
     336      return ownerStr; 
     337    } 
     338 
     339    if (whoType == "other") { 
     340      return otherStr; 
     341    } 
     342 
     343    return "***************" + whoType; 
     344  } 
     345 
     346  this.toXml = function() { 
     347    var w = this.format(); 
     348 
     349    if (whoType == "other") { 
     350      return "    <D:invert>\n        <D:principal><D:owner/></D:principal>\n      </D:invert>"; 
     351    } 
     352 
     353    var res = "    <D:principal>\n"; 
     354 
     355    if (w.indexOf(principalPrefix) == "0") { 
     356      res += "      <D:href>" + w + "</D:href>\n"; 
     357    } else if (whoType == "auth") { 
     358      res += "      <D:authenticated/>\n"; 
     359    } else if (whoType == "unauth") { 
     360      res += "      <D:unauthenticated/>\n"; 
     361    } else if (whoType == "owner") { 
     362      res += "    <D:property><D:owner/></D:property>\n"; 
     363    } else { 
     364      res += "************??????" + whoType; 
     365    } 
     366 
     367    return res + "    </D:principal>\n"; 
     368  } 
     369 
     370  this.equals = function(pr) { 
     371    if (this.whoType != pr.whoType) { 
     372      return false; 
     373    } 
     374 
     375    return this.who == pr.who; 
     376  } 
     377} 
     378 
     379/* METHOD TWO FUNCTIONS*/ 
     380// Access Control Entry (ACE) object 
     381 
     382function bwAce(who, whoType, how, inherited, invert) { 
     383  this.principal = new bwPrincipal(who, whoType); 
    229384  this.how = how; 
    230385  this.inherited = inherited; 
     
    232387 
    233388  this.equals = function(ace) { 
    234     if (this.whoType != ace.whoType) { 
    235       return false; 
    236     } 
    237  
    238     return (this.formatWho() == ace.formatWho()); 
     389    return this.principal.equals(ace.principal); 
    239390  } 
    240391 
    241392  // format the who string for on-screen display 
    242393  this.formatWho = function() { 
    243     if (whoType == "user" || whoType == "group") { 
    244       return who; 
    245     } 
    246  
    247     if (whoType == "auth") { 
    248       return authenticatedStr; 
    249     } 
    250  
    251     if (whoType == "unauth") { 
    252       return unauthenticatedStr; 
    253     } 
    254  
    255     if (whoType == "owner") { 
    256       return ownerStr; 
    257     } 
    258  
    259     if (whoType == "other") { 
    260       return otherStr; 
    261     } 
    262  
    263     return "***************" + whoType; 
    264   } 
    265  
    266   this.toXml = function() { 
    267     var res = "<ace><principal>\n"; 
    268  
    269     if (whoType == "user" || whoType == "group") { 
    270       res += "<href>" + who + "</href>"; 
    271     } else if (whoType == "auth") { 
    272       res += "<property>" + who + "</property>"; 
    273     }else if (whoType == "unauth") { 
    274       res += "<property>" + who + "</property>"; 
    275     } if (whoType == "owner") { 
    276       res += "<property>" + who + "</property>"; 
    277     } if (whoType == "other") { 
    278       res += "<invert><principal>" + who + "</principal></invert>"; 
    279     } 
    280     res += "</principal>"; 
    281     res += "<grant>"; 
    282     res += "<read/>"; 
    283     res += "</grant>"; 
    284  
    285     if (this.inherited != '') { 
    286       res += "<inherited><href>" + this.inherited + "</href></inherited>"; 
    287     } 
    288  
    289     return res + "</ace>"; 
     394    return this.principal.format(); 
    290395  } 
    291396 
     
    294399    var formattedHow = ""; 
    295400 
    296     for (i = 0; i < how.length; i++) { 
     401    for (var i = 0; i < how.length; i++) { 
    297402      var h = how[i]; 
     403      var negated = false; 
    298404      if (h == "-") { 
    299         formattedHow += "not-"; 
     405        negated = true; 
     406        i++; 
     407        h = how[i]; 
     408      } 
     409 
     410      formattedHow += hows.getHows(h).getDispVal(negated) + " "; 
     411    } 
     412 
     413    return formattedHow; 
     414  } 
     415 
     416  this.formatInherited = function() { 
     417    if (inherited != "") { 
     418      return inherited; 
     419    } 
     420 
     421    return inheritedStr; 
     422  } 
     423 
     424  this.howsToXml = function(doGrants) { 
     425    var open = false; 
     426 
     427    for (var hi = 0; hi < how.length; hi++) { 
     428      var h = how[hi]; 
     429      var res = ""; 
     430 
     431      if (doGrants && (h == "-")) { 
     432        // skip 
     433        hi++; 
     434      } else if (!doGrants && (h != "-")) { 
     435        // skip 
    300436      } else { 
     437        if (h == "-") { 
     438          hi++; 
     439          h = how[hi]; 
     440        } 
     441 
    301442        var hvs = hows.getHows(h); 
    302443 
    303         formattedHow += hvs.dispVal + " "; 
    304       } 
    305     } 
    306  
    307     return formattedHow; 
     444        if (!open) { 
     445          if (doGrants) { 
     446            res += "    <D:grant>\n"; 
     447          } else { 
     448            res += "    <D:deny>\n"; 
     449          } 
     450 
     451          open = true; 
     452        } 
     453 
     454        res += "      <D:privilege>" + hvs.davEl + "</D:privilege>\n"; 
     455      } 
     456    } 
     457 
     458    if (open) { 
     459      if (doGrants) { 
     460        res += "    </D:grant>\n"; 
     461      } else { 
     462        res += "    </D:deny>\n"; 
     463      } 
     464    } 
     465 
     466    return res; 
     467  } 
     468 
     469  this.toXml = function() { 
     470    var res = "  <D:ace>\n" + this.principal.toXml(); 
     471 
     472    res += this.howsToXml(true); 
     473    res += this.howsToXml(false); 
     474 
     475    if (this.inherited != "") { 
     476      res += "    <D:inherited><D:href>" + this.inherited + "</D:href></D:inherited>"; 
     477    } 
     478 
     479    return res + "  </D:ace>\n"; 
     480  } 
     481 
     482  this.toFormRow = function(row) { 
     483    row.insertCell(0).appendChild(document.createTextNode(this.principal.format())); 
     484    row.insertCell(1).appendChild(document.createTextNode(this.formatHow())); 
     485    row.insertCell(2).appendChild(document.createTextNode(this.formatInherited())); 
     486    var td_3 = row.insertCell(3); 
     487    td_3.appendChild(document.createTextNode('')); 
     488    //<a href="javascript:bwAcl.delete(' + j +')">' + deleteStr + '</a> 
    308489  } 
    309490} 
     
    317498  // The function expects a comma-separated list of arguments grouped 
    318499  // into the five ACE properties. 
    319   this.init = function(who,whoType,how,inherited,invert) { 
    320     aces.push(new bwAce(who,whoType,how,inherited,invert)); 
     500  this.init = function(who, whoType, how, inherited, invert) { 
     501    aces.push(new bwAce(who, whoType, how, inherited, invert)); 
    321502  } 
    322503 
     
    344525      } 
    345526    } 
     527 
    346528    // validate for user or group 
    347529    if ((type == 'user' || type == 'group') && formObj.who.value == '') { 
     
    350532      return; 
    351533    } 
    352     // return the how string from the form 
    353     var how = setAccessHow(formObj,2); 
    354     // update the bwAcl 
    355     bwAcl.addAce(new bwAce(formObj.who.value,type,how,"local",false)); 
     534 
     535    // get the how string from the form 
     536    var how = setAccessHow(formObj, 2); 
     537 
     538    //alert("About to update who=" + formObj.who.value + 
     539    //       "\ntype= " + type + "\nhow=" + how); 
     540 
     541    bwAcl.addAce(new bwAce(formObj.who.value, type, how, "" , false)); 
     542    formObj.who.value = ""; 
     543 
     544    // update the acl form field 
     545    formObj.acl.value = this.toXml(); 
     546 
     547    // redraw the display 
     548    this.display(); 
     549  } 
     550 
     551  this.deleteAce = function(index) { 
     552    bwAcl.aces.splice(index, 1); 
    356553 
    357554    // update the acl form field 
    358555    formObj.acl = this.toXml(); 
    359  
    360     // redraw the display 
    361     this.display(); 
    362   } 
    363  
    364   this.deleteAce = function(index) { 
    365     bwAcl.aces.splice(index, 1); 
    366556 
    367557    // redraw the display 
     
    382572      // recreate the table rows 
    383573      for (var j = 0; j < aces.length; j++) { 
    384         var formattedWho = aces[j].formatWho(); 
    385         var formattedHow = aces[j].formatHow(); 
     574        var curAce = aces[j]; 
    386575        var tr = aclTableBody.insertRow(j); 
    387576 
    388         tr.insertCell(0).appendChild(document.createTextNode(formattedWho)); 
    389         tr.insertCell(1).appendChild(document.createTextNode(formattedHow)); 
    390         tr.insertCell(2).appendChild(document.createTextNode(aces[j].inherited)); 
    391         var td_3 = tr.insertCell(3); 
    392         td_3.appendChild(document.createTextNode('')); 
    393         //<a href="javascript:bwAcl.delete(' + j +')">' + deleteStr + '</a> 
     577        curAce.toFormRow(tr); 
    394578      } 
    395579    } catch (e) { 
     
    400584  // generate webDAV ACl XML output 
    401585  this.toXml = function() { 
    402     var res = "<acl>\n"; 
     586    var res = xmlHeader + "\n<D:acl " + nameSpaces + " >\n"; 
    403587 
    404588    for (var j = 0; j < aces.length; j++) { 
     
    406590    } 
    407591 
    408     return res + "</acl>"; 
    409   } 
    410 
    411  
    412  
    413  
    414  
     592    return res + "</D:acl>"; 
     593  } 
     594
     595 
  • trunk/deployment/webuser/webapp/resources/demoskins/resources/bedeworkEventForm.js

    r1445 r1448  
    3535  setRecurrence(formObj); 
    3636  setAccessHow(formObj,1); 
    37   setAccessAcl(formObj); 
     37  //setAccessAcl(formObj); 
    3838} 
    3939function setDates(formObj) {