xowiki::Package instproc make_link (public)

 <instance of xowiki::Package[i]> make_link \
    [ -with_entities with_entities ] [ -privilege privilege ] \
    [ -link link ] object [ method ] args [ args... ]

Defined in packages/xowiki/tcl/package-procs.tcl

Creates conditionally a link for use in xowiki. When the generated link will be activated, the specified method of the object will be invoked. make_link checks in advance, whether the actual user has enough rights to invoke the method. If not, this method returns empty.

Switches:
-with_entities
(defaults to "0") (optional)
-privilege
(optional)
When provided, the privilege can be "public" (do not check rights) or a privilege to be checked on the package_id and the current user. When this parameter is not specified, the policy is used to determine the rights to be checked.
-link
(optional)
When this parameter is specified, is used used as base link for export_vars when applied on pages (or for packages as next segment under the package url). When not specified, the base url for pages is the current url, and for packages it is the package url.
Parameters:
object - The object to which the link refers to. If it is a package_id it will base to the root_url of the package_id. If it is a page, it will base to the page_url
method (optional) - Which method to use. This will be appended as "m=method" to the url. Examples for methods:
  • view: To view and existing page
  • edit: To edit an existing page
  • revisions: To view the revisions of an existing page

args - List of attributes to be append to the link. Every element can be an attribute name, or a "name value" pair. Behaves like export_vars.
Returns:
The link or empty
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_xowiki_test_cases xowiki_test_cases (test xowiki) xowiki::Package instproc make_link xowiki::Package instproc make_link test_xowiki_test_cases->xowiki::Package instproc make_link ad_try ad_try (public) xowiki::Package instproc make_link->ad_try

Testcases:
xowiki_test_cases
Source code:

set computed_link ""

if {[$object istype ::xowiki::Package]} {
  set base ${:package_url}
  if {$method ne ""} {
    #
    # Convention for calling methods on the package.
    #
    lappend args [list $method 1]
  }
  if {[info exists link]} {
    set computed_link [uplevel export_vars -base [list $base$link] [list $args]]
  } else {
    set computed_link [uplevel export_vars -base [list $base] [list $args]]
  }
} elseif {[$object istype ::xowiki::Page]} {
  if {[info exists link]} {
    set base $link
  } else {
    #
    # Use the provided object for computing the base URL.
    #
    set base [$object pretty_link]
    #
    # Before, we had
    #
    #    set base ${:url}
    #
    # which depends on the invocation context.
    #
  }
  if {$method ne ""} {
    #
    # Convention for calling methods on an xowiki::Page
    #
    lappend args [list m $method]
  }
  #set computed_link [uplevel export_vars -base [list $base] -no_base_encode [list $args]]
  set computed_link [uplevel [list export_vars -base $base -no_base_encode $args]]
  #:msg "computed_link = '$computed_link'"
}
if {$with_entities} {
  regsub -all & $computed_link "&amp;" computed_link
}

# provide links based in untrusted_user_id
set party_id [::xo::cc set untrusted_user_id]
if {[info exists privilege]} {
  #:log "-- checking priv $privilege for [self args] from id ${:id}"
  set granted [expr {$privilege eq "public" ? 1 :
                     [::xo::cc permission -object_id ${:id} -privilege $privilege -party_id $party_id] }]
} else {
  # determine privilege from policy
  #:msg "-- check permissions from ${:id} of object $object $method"
  ad_try {
    set granted [:check_permissions  -user_id $party_id  -package_id ${:id}  -link $computed_link $object $method]
  } on error {errorMsg} {
    ns_log error "error in check_permissions: $errorMsg"
    set granted 0
  }
  #:msg "--p ${:id} check_permissions $object $method ==> $granted"
}
#:log "granted=$granted $computed_link"
if {$granted} {
  return $computed_link
}
return ""
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: