conversions

package
v2.19.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package conversions sits between CS3 type definitions and OCS API Responses

Package conversions sits between CS3 type definitions and OCS API Responses

Index

Constants

View Source
const (
	// ShareTypeUser refers to user shares
	ShareTypeUser ShareType = 0

	// ShareTypePublicLink refers to public link shares
	ShareTypePublicLink ShareType = 3

	// ShareTypeGroup represents a group share
	ShareTypeGroup ShareType = 1

	// ShareTypeFederatedCloudShare represents a federated share
	ShareTypeFederatedCloudShare ShareType = 6

	// ShareTypeSpaceMembershipUser represents an action regarding user type space members
	ShareTypeSpaceMembershipUser ShareType = 7

	// ShareTypeSpaceMembershipGroup represents an action regarding group type space members
	ShareTypeSpaceMembershipGroup ShareType = 8

	// ShareWithUserTypeUser represents a normal user
	ShareWithUserTypeUser ShareWithUserType = 0

	// ShareWithUserTypeGuest represents a guest user
	ShareWithUserTypeGuest ShareWithUserType = 1
)
View Source
const (
	// RoleViewer grants non-editor role on a resource.
	RoleViewer = "viewer"
	// RoleSpaceViewer grants non-editor role on a space.
	RoleSpaceViewer = "spaceviewer"
	// RoleEditor grants editor permission on a resource, including folders.
	RoleEditor = "editor"
	// RoleSpaceEditor grants editor permission on a space.
	RoleSpaceEditor = "spaceeditor"
	// RoleFileEditor grants editor permission on a single file.
	RoleFileEditor = "file-editor"
	// RoleCoowner grants co-owner permissions on a resource.
	RoleCoowner = "coowner"
	// RoleUploader grants uploader permission to upload onto a resource.
	RoleUploader = "uploader"
	// RoleManager grants manager permissions on a resource. Semantically equivalent to co-owner.
	RoleManager = "manager"

	// RoleUnknown is used for unknown roles.
	RoleUnknown = "unknown"
	// RoleLegacy provides backwards compatibility.
	RoleLegacy = "legacy"
	// RoleDenied grants no permission at all on a resource
	RoleDenied = "denied"
)

Variables

View Source
var (
	// ErrPermissionNotInRange defines a permission specific error.
	ErrPermissionNotInRange = fmt.Errorf("The provided permission is not between %d and %d", PermissionMinInput, PermissionMaxInput)
	// ErrZeroPermission defines a permission specific error
	ErrZeroPermission = errors.New("permission is zero")
)

Functions

func GetPublicShareManager

func GetPublicShareManager(manager string, m map[string]map[string]interface{}) (publicshare.Manager, error)

GetPublicShareManager returns a connection to a public share manager

func GetUserManager

func GetUserManager(manager string, m map[string]map[string]interface{}) (user.Manager, error)

GetUserManager returns a connection to a user share manager

func LocalGroupIDToString

func LocalGroupIDToString(groupID *grouppb.GroupId) string

LocalGroupIDToString transforms a cs3api group id into an ocs data model without domain name

func LocalUserIDToString

func LocalUserIDToString(userID *userpb.UserId) string

LocalUserIDToString transforms a cs3api user id into an ocs data model without domain name TODO ocs uses user names ... so an additional lookup is needed. see mapUserIds()

func ParseTimestamp

func ParseTimestamp(timestampString string) (*types.Timestamp, error)

ParseTimestamp tries to parse the ocs expiry into a CS3 Timestamp

func SufficientCS3Permissions

func SufficientCS3Permissions(existing, requested *provider.ResourcePermissions) bool

SufficientCS3Permissions returns true if the `existing` permissions contain the `requested` permissions

func UserTypeString

func UserTypeString(userType userpb.UserType) string

UserTypeString returns human readable strings for various user types

Types

type ExactMatchesData

type ExactMatchesData struct {
	Users   []*MatchData `json:"users" xml:"users>element"`
	Groups  []*MatchData `json:"groups" xml:"groups>element"`
	Remotes []*MatchData `json:"remotes" xml:"remotes>element"`
}

ExactMatchesData hold exact matches

type MatchData

type MatchData struct {
	Label string          `json:"label" xml:"label,omitempty"`
	Value *MatchValueData `json:"value" xml:"value"`
}

MatchData describes a single match

type MatchValueData

type MatchValueData struct {
	ShareType               int    `json:"shareType" xml:"shareType"`
	ShareWith               string `json:"shareWith" xml:"shareWith"`
	ShareWithProvider       string `json:"shareWithProvider" xml:"shareWithProvider"`
	ShareWithAdditionalInfo string `json:"shareWithAdditionalInfo" xml:"shareWithAdditionalInfo,omitempty"`
	UserType                int    `json:"userType" xml:"userType"`
}

MatchValueData holds the type and actual value

type Permissions

type Permissions uint

Permissions reflects the CRUD permissions used in the OCS sharing API

const (
	// PermissionInvalid represents an invalid permission
	PermissionInvalid Permissions = 0
	// PermissionRead grants read permissions on a resource
	PermissionRead Permissions = 1 << (iota - 1)
	// PermissionWrite grants write permissions on a resource
	PermissionWrite
	// PermissionCreate grants create permissions on a resource
	PermissionCreate
	// PermissionDelete grants delete permissions on a resource
	PermissionDelete
	// PermissionShare grants share permissions on a resource
	PermissionShare
	// PermissionAll grants all permissions on a resource
	PermissionAll Permissions = (1 << (iota - 1)) - 1
	// PermissionMaxInput is to be used within value range checks
	PermissionMaxInput = PermissionAll
	// PermissionMinInput is to be used within value range checks
	PermissionMinInput = PermissionRead
	// PermissionsNone is to be used to deny access on a resource
	PermissionsNone = 64
)

func NewPermissions

func NewPermissions(val int) (Permissions, error)

NewPermissions creates a new Permissions instance. The value must be in the valid range.

func (Permissions) Contain

func (p Permissions) Contain(other Permissions) bool

Contain tests if the permissions contain another one.

func (Permissions) String

func (p Permissions) String() string

type ResourceType

type ResourceType int

ResourceType indicates the OCS type of the resource

func (ResourceType) String

func (rt ResourceType) String() (s string)

type Role

type Role struct {
	Name string
	// contains filtered or unexported fields
}

Role is a set of ocs permissions and cs3 resource permissions under a common name.

func NewCoownerRole

func NewCoownerRole() *Role

NewCoownerRole creates a coowner role.

func NewDeniedRole

func NewDeniedRole() *Role

NewDeniedRole creates a fully denied role

func NewEditorRole

func NewEditorRole(sharing bool) *Role

NewEditorRole creates an editor role. `sharing` indicates if sharing permission should be added

func NewFileEditorRole

func NewFileEditorRole(sharing bool) *Role

NewFileEditorRole creates a file-editor role

func NewLegacyRoleFromOCSPermissions

func NewLegacyRoleFromOCSPermissions(p Permissions) *Role

NewLegacyRoleFromOCSPermissions tries to map a legacy combination of ocs permissions to cs3 resource permissions as a legacy role

func NewManagerRole

func NewManagerRole() *Role

NewManagerRole creates an manager role

func NewNoneRole

func NewNoneRole() *Role

NewNoneRole creates a role with no permissions

func NewSpaceEditorRole

func NewSpaceEditorRole() *Role

NewSpaceEditorRole creates an editor role

func NewSpaceViewerRole

func NewSpaceViewerRole() *Role

NewSpaceViewerRole creates a spaceviewer role

func NewUnknownRole

func NewUnknownRole() *Role

NewUnknownRole creates an unknown role. An Unknown role has no permissions over a cs3 resource nor any ocs endpoint.

func NewUploaderRole

func NewUploaderRole() *Role

NewUploaderRole creates an uploader role

func NewViewerRole

func NewViewerRole(sharing bool) *Role

NewViewerRole creates a viewer role. `sharing` indicates if sharing permission should be added

func RoleFromName

func RoleFromName(name string, sharing bool) *Role

RoleFromName creates a role from the name

func RoleFromOCSPermissions

func RoleFromOCSPermissions(p Permissions, ri *provider.ResourceInfo) *Role

RoleFromOCSPermissions tries to map ocs permissions to a role TODO: rethink using this. ocs permissions cannot be assigned 1:1 to roles

func RoleFromResourcePermissions

func RoleFromResourcePermissions(rp *provider.ResourcePermissions, islink bool) *Role

RoleFromResourcePermissions tries to map cs3 resource permissions to a role It needs to know whether this is a link or not, because empty permissions on links mean "INTERNAL LINK" while empty permissions on other resources mean "DENIAL". Obviously this is not optimal.

func (*Role) CS3ResourcePermissions

func (r *Role) CS3ResourcePermissions() *provider.ResourcePermissions

CS3ResourcePermissions for the role

func (*Role) OCSPermissions

func (r *Role) OCSPermissions() Permissions

OCSPermissions for the role

func (*Role) WebDAVPermissions

func (r *Role) WebDAVPermissions(isDir, isShared, isMountpoint, isPublic bool) string

WebDAVPermissions returns the webdav permissions used in propfinds, eg. "WCKDNVR"

from https://github.com/owncloud/core/blob/10715e2b1c85fc3855a38d2b1fe4426b5e3efbad/apps/dav/lib/Files/PublicFiles/SharedNodeTrait.php#L196-L215

	$p = '';
	if ($node->isDeletable() && $this->checkSharePermissions(Constants::PERMISSION_DELETE)) {
		$p .= 'D';
	}
	if ($node->isUpdateable() && $this->checkSharePermissions(Constants::PERMISSION_UPDATE)) {
		$p .= 'NV'; // Renameable, Moveable
	}
	if ($node->getType() === \OCP\Files\FileInfo::TYPE_FILE) {
		if ($node->isUpdateable() && $this->checkSharePermissions(Constants::PERMISSION_UPDATE)) {
			$p .= 'W';
		}
	} else {
		if ($node->isCreatable() && $this->checkSharePermissions(Constants::PERMISSION_CREATE)) {
			$p .= 'CK';
		}
	}

D = delete NV = update (renameable moveable) W = update (files only) CK = create (folders only) S = Shared R = Shareable M = Mounted Z = Deniable (NEW) P = Purge from trashbin

type ShareData

type ShareData struct {
	// TODO int?
	ID string `json:"id" xml:"id"`
	// The share’s type
	ShareType ShareType `json:"share_type" xml:"share_type"`
	// The username of the owner of the share.
	UIDOwner string `json:"uid_owner" xml:"uid_owner"`
	// The display name of the owner of the share.
	DisplaynameOwner string `json:"displayname_owner" xml:"displayname_owner"`
	// Additional info to identify the share owner, eg. the email or username
	AdditionalInfoOwner string `json:"additional_info_owner" xml:"additional_info_owner"`
	// The permission attribute set on the file.
	// TODO(jfd) change the default to read only
	Permissions Permissions `json:"permissions" xml:"permissions"`
	// The UNIX timestamp when the share was created.
	STime uint64 `json:"stime" xml:"stime"`
	// ?
	Parent string `json:"parent" xml:"parent"`
	// The UNIX timestamp when the share expires.
	Expiration string `json:"expiration" xml:"expiration"`
	// The public link to the item being shared.
	Token string `json:"token" xml:"token"`
	// The unique id of the user that owns the file or folder being shared.
	UIDFileOwner string `json:"uid_file_owner" xml:"uid_file_owner"`
	// The display name of the user that owns the file or folder being shared.
	DisplaynameFileOwner string `json:"displayname_file_owner" xml:"displayname_file_owner"`
	// Additional info to identify the file owner, eg. the email or username
	AdditionalInfoFileOwner string `json:"additional_info_file_owner" xml:"additional_info_file_owner"`
	// share state, 0 = accepted, 1 = pending, 2 = declined
	State int `json:"state" xml:"state"`
	// The path to the shared file or folder.
	Path string `json:"path" xml:"path"`
	// The type of the object being shared. This can be one of 'file' or 'folder'.
	ItemType string `json:"item_type" xml:"item_type"`
	// The RFC2045-compliant mimetype of the file.
	MimeType string `json:"mimetype" xml:"mimetype"`
	// The space ID of the original file location
	SpaceID string `json:"space_id" xml:"space_id"`
	// The space alias of the original file location
	SpaceAlias string `json:"space_alias" xml:"space_alias"`
	StorageID  string `json:"storage_id" xml:"storage_id"`
	Storage    uint64 `json:"storage" xml:"storage"`
	// The unique node id of the item being shared.
	ItemSource string `json:"item_source" xml:"item_source"`
	// The unique node id of the item being shared. For legacy reasons item_source and file_source attributes have the same value.
	FileSource string `json:"file_source" xml:"file_source"`
	// The unique node id of the parent node of the item being shared.
	FileParent string `json:"file_parent" xml:"file_parent"`
	// The basename of the shared file.
	FileTarget string `json:"file_target" xml:"file_target"`
	// The uid of the share recipient. This is either
	// - a GID (group id) if it is being shared with a group or
	// - a UID (user id) if the share is shared with a user.
	// - a password for public links
	ShareWith string `json:"share_with,omitempty" xml:"share_with,omitempty"`
	// The type of user
	// - 0 = normal user
	// - 1 = guest account
	ShareWithUserType ShareWithUserType `json:"share_with_user_type" xml:"share_with_user_type"`
	// The display name of the share recipient
	ShareWithDisplayname string `json:"share_with_displayname,omitempty" xml:"share_with_displayname,omitempty"`
	// Additional info to identify the share recipient, eg. the email or username
	ShareWithAdditionalInfo string `json:"share_with_additional_info" xml:"share_with_additional_info"`
	// Whether the recipient was notified, by mail, about the share being shared with them.
	MailSend int `json:"mail_send" xml:"mail_send"`
	// Name of the public share
	Name string `json:"name" xml:"name"`
	// URL of the public share
	URL string `json:"url,omitempty" xml:"url,omitempty"`
	// Attributes associated
	Attributes string `json:"attributes,omitempty" xml:"attributes,omitempty"`
	// Quicklink indicates if the link is the quicklink
	Quicklink bool `json:"quicklink,omitempty" xml:"quicklink,omitempty"`
	// PasswordProtected represents a public share is password protected
	// PasswordProtected bool `json:"password_protected,omitempty" xml:"password_protected,omitempty"`
	Hidden bool `json:"hidden" xml:"hidden"`
}

ShareData represents https://doc.owncloud.com/server/developer_manual/core/ocs-share-api.html#response-attributes-1

func CS3Share2ShareData

func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) *ShareData

CS3Share2ShareData converts a cs3api user share into shareData data model

func OCMShare2ShareData

func OCMShare2ShareData(share *ocm.Share) (*ShareData, error)

OCMShare2ShareData converts a cs3 ocm share into a share data model.

func PublicShare2ShareData

func PublicShare2ShareData(share *link.PublicShare, r *http.Request, publicURL string) *ShareData

PublicShare2ShareData converts a cs3api public share into shareData data model

func ReceivedOCMShare2ShareData

func ReceivedOCMShare2ShareData(share *ocm.ReceivedShare, path string) (*ShareData, error)

ReceivedOCMShare2ShareData converts a cs3 ocm received share into a share data model.

type ShareType

type ShareType int

ShareType denotes a type of share

type ShareWithUserType

type ShareWithUserType int

ShareWithUserType denotes a type of user

type ShareeData

type ShareeData struct {
	Exact   *ExactMatchesData `json:"exact" xml:"exact"`
	Users   []*MatchData      `json:"users" xml:"users>element"`
	Groups  []*MatchData      `json:"groups" xml:"groups>element"`
	Remotes []*MatchData      `json:"remotes" xml:"remotes>element"`
}

ShareeData holds share recipient search results

type TokenInfo

type TokenInfo struct {
	// for all callers
	Token             string `json:"token" xml:"token"`
	LinkURL           string `json:"link_url" xml:"link_url"`
	PasswordProtected bool   `json:"password_protected" xml:"password_protected"`
	Aliaslink         bool   `json:"alias_link" xml:"alias_link"`

	// if not password protected
	ID        string `json:"id" xml:"id"`
	StorageID string `json:"storage_id" xml:"storage_id"`
	SpaceID   string `json:"space_id" xml:"space_id"`
	OpaqueID  string `json:"opaque_id" xml:"opaque_id"`
	Path      string `json:"path" xml:"path"`

	// if native access
	SpacePath  string `json:"space_path" xml:"space_path"`
	SpaceAlias string `json:"space_alias" xml:"space_alias"`
	SpaceURL   string `json:"space_url" xml:"space_url"`
	SpaceType  string `json:"space_type" xml:"space_type"`
}

TokenInfo holds token information

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL