Previous topic

5.1.8. controllers.part — Controllers for parts

Next topic

5.1.10. controllers.user — Controllers for users

This Page

Languages

Previous versions

1.2
1.1

5.1.9. controllers.plmobject — Controllers for plmobjects

class plmapp.controllers.plmobject.PLMObjectController(obj, user, block_mails=False, no_index=False)[source]

Bases: openPLM.plmapp.controllers.base.Controller

Object used to manage a PLMObject and store his modification in a history

Attributes :
object

The PLMObject managed by the controller

_user

User who modifies object

Parameters:
  • obj (a subinstance of PLMObject) – managed object
  • user (User) – user who modifies obj
HISTORY

alias of History

classmethod create(reference, type, revision, user, data={}, block_mails=False, no_index=False)[source]

This method builds a new PLMObject of type class_ and return a PLMObjectController associated to the created object.

Raises ValueError if reference, type or revision are empty. Raises ValueError if type is not valid.

Parameters:
  • reference – reference of the objet
  • type – type of the object
  • revision – revision of the object
  • user – user who creates/owns the object
  • data – a dict<key, value> with informations to add to the plmobject
Return type:

PLMObjectController

classmethod create_from_form(form, user, block_mails=False, no_index=False)[source]

Creates a PLMObjectController from form and associates user as the creator/owner of the PLMObject.

This method raises ValueError if form is invalid.

Parameters:
  • form – a django form associated to a model
  • user – user who creates/owns the object
Return type:

PLMObjectController

classmethod load(type, reference, revision, user)[source]
can_approve_promotion(user=None)[source]
get_represented_approvers(user=None)[source]
is_last_promoter()[source]
approve_promotion()[source]
discard_approvals()[source]
promote(checked=False)[source]

Promotes object in its lifecycle and writes its promotion in the history

Raise :PromotionError if object is not promotable
Raise :PermissionError if the use can not sign object
Returns:a dictionary with two keys:
new_state
the new current State of the object
updated_revisions
a list of updated (deprecated or cancelled) revisions
demote()[source]

Demotes object in irs lifecycle and writes irs demotion in the history

Raise :PermissionError if the use can not sign object
has_permission(role)[source]
check_editable()[source]

Raises a PermissionError if object is not editable.

check_in_group(user, raise_=True)[source]

New in version 1.0.1.

Checks that user belongs to the object’s group.

Returns True if the user belongs to the group. Otherwise, returns False if raise_ is False or raises a PermissionError if raise_ is True.

Note that it always returns True if user is the company.

revise(new_revision, group=None)[source]

Makes a new revision: duplicates object. The duplicated object’s revision is new_revision.

Returns a controller of the new object.

is_revisable(check_user=True)[source]

Returns True if object is revisable: if revise() can be called safely.

If check_user is True (the default), it also checks if _user can see the object.

get_previous_revisions()[source]
get_next_revisions()[source]
get_all_revisions()[source]

Returns a list of all revisions, ordered from less recent to most recent

Return type:list of PLMObject
set_owner(new_owner, dirty=False)[source]

Sets new_owner as current owner.

Note

This method does NOT check that the current user is the owner of the object. set_role() does that check.

Parameters:
  • new_owner (User) – the new owner
  • dirty – True if set_owner should skip sanity checks and should not send a mail (usefull for tests, default is False)
Raise :

PermissionError if new_owner is not a contributor

Raise :

ValueError if new_owner is the company and the object is editable

Changed in version 1.0.1.

Raise :PermissionError if new_owner does not belong to the object’s group.
add_notified(new_notified)[source]

Adds new_notified to the list of users notified when object changes.

Parameters:new_notified (User) – the new user who would be notified
Raise :IntegrityError if new_notified is already notified when object changes

Changed in version 1.0.1.

Raise :PermissionError if new_notified does not belong to the object’s group.
add_reader(new_reader)[source]
check_edit_signer(raise_=True)[source]

New in version 1.2.

Checks that the current user can edit the signers of the object:

  • He must own the object
  • No user should have approved the promotion
Raise :PermissionError if raise_ is True and one of the above conditions is not met
Returns:True if the user can edit the signers
can_edit_signer()[source]

New in version 1.2.

Returns True if the user can edit signers of the object.

check_signer(user, role)[source]

New in version 1.2.

Checks that user can become a signer.

Raise :PermissionError if user is not a contributor
Raise :PermissionError if user is not in the object’s group
Raise :ValueError if role is not a valid signer role according to the object’s lifecycle
add_signer(new_signer, role)[source]

New in version 1.2.

Adds new_signer to the list of signer for the role role.

Raise :exceptions raised by check_edit_signer()
Raise :exceptions raised by check_signer()
remove_notified(notified)[source]

Removes notified to the list of users notified when object changes.

Parameters:notified (User) – the user who would be no more notified
Raise :ObjectDoesNotExist if notified is not notified when object changes
remove_reader(reader)[source]

Removes reader to the list of restricted readers when object changes.

Parameters:reader (User) – the user who would be no more reader
Raise :ObjectDoesNotExist if reader is not reader
remove_signer(signer, role)[source]

New in version 1.2.

Removes signer to the list of signers for role role.

Parameters:

signer (User) – the user who would be no more signer

Raise :

PermissionError if:

  • user is not the owner
  • one signer has approved the promotion
  • there is only one signer
Raise :

ObjectDoesNotExist if signer is not a signer

replace_signer(old_signer, new_signer, role)[source]

New in version 1.2.

Sets new_signer as current signer instead of old_signer for role. role must be a valid sign role (see level_to_sign_str() to get a role from a sign level (int)).

Parameters:
  • old_signer (User) – the replaced signer
  • new_signer (User) – the new signer
  • role (str) – the sign role
Raise :

PermissionError if signer is not a contributor

Raise :

PermissionError if new_signer does not belong to the object’s group.

Raise :

ValueError if role is invalid (level to high)

set_role(user, role)[source]

Sets role role (like owner or notified) for user

Note

If role is ROLE_OWNER, the previous owner is replaced by user.

Raise :ValueError if role is invalid
Raise :PermissionError if user is not allowed to has role role
remove_user(link)[source]
check_permission(role, raise_=True)[source]
check_readable(raise_=True)[source]

Returns True if the user can read (is allowed to) this object.

Raises a PermissionError if the user cannot read the object and raise_ is True (the default).

check_restricted_readable(raise_=True)[source]

Returns True if the user can read (is allowed to) the restricted data of this object.

Raises a PermissionError if the user cannot read the object and raise_ is True (the default).

cancel()[source]

Cancels the object:

  • Its lifecycle becomes “cancelled”.
  • Its owner becomes the company.
  • It removes all signer.
check_publish(raise_=True)[source]

New in version 1.1.

Checks that an object can be published.

If raise_ is True:

raise:PermissionError if the object is not official
raise:PermissionError if the user is not allowed to publish an object (see UserProfile.can_publish)
raise:PermissionError if the user does not belong to the object’s group
raise:ValueError if the object is already published

If raise_ is False:

Returns True if all previous tests has been succesfully passed, False otherwise.
can_publish()[source]

New in version 1.1.

Returns True if the user can publish this object.

publish()[source]

New in version 1.1.

Publish the object.

A published object can be accessed by anonymous users.

Raise :all exceptions raised by check_publish()
check_unpublish(raise_=True)[source]

New in version 1.1.

Checks that an object can be unpublished.

If raise_ is True:

raise:PermissionError if the user is not allowed to unpublish an object (see UserProfile.can_publish)
raise:PermissionError if the user does not belong to the object’s group
raise:ValueError if the object is unpublished

If raise_ is False:

Returns True if all previous tests has been succesfully passed, False otherwise.
can_unpublish()[source]

New in version 1.1.

Returns True if the user can unpublish this object.

unpublish()[source]

New in version 1.1.

Unpublish the object.

Raise :all exceptions raised by check_unpublish()
check_cancel(raise_=True)[source]

New in version 1.1.

Checks that an object can be cancelled.

If raise_ is True:

raise:PermissionError if the object is not draft
raise:PermissionError if the object has related previous or next revision
raise:PermissionError if the user has not owner rights on an object

If raise_ is False:

Returns True if all previous tests has been succesfully passed, False otherwise.
can_cancel()[source]

New in version 1.1.

Returns True if the user can cancel this object.

safe_cancel()[source]
check_clone(raise_=True)[source]

New in version 1.1.

Checks that an object can be cloned.

If raise_ is True:

raise:PermissionError if the object is not readable
raise:PermissionError if the object can not be read
raise:PermissionError if the object is not cloneable

If raise_ is False:

Returns True if all previous tests has been succesfully passed, False otherwise.
can_clone()[source]

New in version 1.1.

Returns True if the user can clone this object.

clone(form, user, block_mails=False, no_index=False)[source]

New in version 1.1.

Clone this object and return the related controller.

Parameters:
  • form – the form sent from clone view
  • user – the user who is cloning the object
histories[source]
object