View Source Lightning.Projects (Lightning v2.10.4)

The Projects context.

Summary

Functions

Returns an %Ecto.Changeset{} for tracking project changes.

Deletes a project and its related data, including workflows, work orders, steps, jobs, runs, triggers, project users, project credentials, and dataclips

Deletes project dataclips in batches

Deletes project work orders in batches

Gets a single project.

Gets a single project_user.

Returns the role of a user in a project. Possible roles are :admin, :viewer, :editor, and :owner

Get all project users for a given project

Gets a single project with it's members via project_users.

Fetches projects for a given user from the database.

Lists emails of users with :owner or :admin roles in the project

Returns the list of projects.

Lists all projects that have history retention

Perform, when called with %{"type" => "purge_deleted"} will find projects that are ready for permanent deletion and purge them.

Builds a query to retrieve projects associated with a user.

Should input or output dataclips be saved for runs in this project?

Given a project, this function sets a scheduled deletion date based on the PURGE_DELETED_AFTER_DAYS environment variable. If no ENV is set, this date defaults to NOW but the automatic project purge cronjob will never run. (Note that subsequent logins will be blocked for projects pending deletion.)

Returns an %Ecto.Changeset{} for changing the project scheduled_deletion.

Functions

Link to this function

add_project_users(project, project_users, notify_users \\ true)

View Source
@spec add_project_users(Lightning.Projects.Project.t(), [map(), ...], boolean()) ::
  {:ok, [Lightning.Projects.ProjectUser.t(), ...]}
  | {:error, Ecto.Changeset.t()}
Link to this function

cancel_scheduled_deletion(project_id)

View Source
Link to this function

change_project(project, attrs \\ %{})

View Source

Returns an %Ecto.Changeset{} for tracking project changes.

Examples

iex> change_project(project)
%Ecto.Changeset{data: %Project{}}
Link to this function

create_project(attrs \\ %{}, schedule_email? \\ true)

View Source

Creates a project.

Examples

iex> create_project(%{field: value})
{:ok, %Project{}}

iex> create_project(%{field: bad_value})
{:error, %Ecto.Changeset{}}

Deletes a project and its related data, including workflows, work orders, steps, jobs, runs, triggers, project users, project credentials, and dataclips

Examples

iex> delete_project(project)
{:ok, %Project{}}

iex> delete_project(project)
{:error, %Ecto.Changeset{}}
Link to this function

delete_project_async(project)

View Source
@spec delete_project_async(Lightning.Projects.Project.t()) :: {:ok, Oban.Job.t()}
Link to this function

delete_project_dataclips(project, batch_size \\ 1000)

View Source
@spec delete_project_dataclips(Lightning.Projects.Project.t(), non_neg_integer()) ::
  :ok

Deletes project dataclips in batches

Link to this function

delete_project_user!(project_user)

View Source
Link to this function

delete_project_workorders(project, batch_size \\ 1000)

View Source
@spec delete_project_workorders(Lightning.Projects.Project.t(), non_neg_integer()) ::
  :ok

Deletes project work orders in batches

Link to this function

export_project(atom, project_id, snapshot_ids \\ nil)

View Source
@spec export_project(atom(), Ecto.UUID.t(), [Ecto.UUID.t()] | nil) :: {:ok, binary()}

Exports a project as yaml.

Examples

iex> export_project(:yaml, project_id)
{:ok, string}
Link to this function

find_users_to_notify_of_trigger_failure(project_id)

View Source

Gets a single project.

Raises Ecto.NoResultsError if the Project does not exist.

Examples

iex> get_project!(123)
%Project{}

iex> get_project!(456)
** (Ecto.NoResultsError)
Link to this function

get_project_credential(project_id, credential_id)

View Source
Link to this function

get_project_user(project, user)

View Source

Gets a single project_user.

Raises Ecto.NoResultsError if the ProjectUser does not exist.

Examples

iex> get_project_user!(123)
%ProjectUser{}

iex> get_project_user!(456)
** (Ecto.NoResultsError)
Link to this function

get_project_user_role(user, project)

View Source

Returns the role of a user in a project. Possible roles are :admin, :viewer, :editor, and :owner

Examples

iex> get_project_user_role(user, project)
:admin

iex> get_project_user_role(user, project)
:viewer

iex> get_project_user_role(user, project)
:editor

iex> get_project_user_role(user, project)
:owner

Get all project users for a given project

Link to this function

get_project_with_users!(id)

View Source

Gets a single project with it's members via project_users.

Raises Ecto.NoResultsError if the Project does not exist.

Examples

iex> get_project!(123)
%Project{}

iex> get_project!(456)
** (Ecto.NoResultsError)
Link to this function

get_projects_for_user(user, opts \\ [])

View Source
@spec get_projects_for_user(user :: Lightning.Accounts.User.t(), opts :: keyword()) ::
  [
    Lightning.Projects.Project.t()
  ]

Fetches projects for a given user from the database.

Parameters

  • user: The user struct for which projects are being queried.
  • opts: Keyword list of options including :include for associations to preload and :order_by for sorting.

Returns

  • A list of projects associated with the user.
Link to this function

get_projects_overview(user, opts \\ [])

View Source
Link to this function

invite_collaborators(project, collaborators, inviter)

View Source
Link to this function

list_project_admin_emails(id)

View Source
@spec list_project_admin_emails(Ecto.UUID.t()) :: [String.t(), ...] | []

Lists emails of users with :owner or :admin roles in the project

Link to this function

list_project_credentials(project)

View Source
@spec list_project_credentials(project :: Lightning.Projects.Project.t()) :: [
  Lightning.Projects.ProjectCredential.t()
]
Link to this function

list_project_files(project, opts \\ [])

View Source

Returns the list of projects.

Examples

iex> list_projects()
[%Project{}, ...]
Link to this function

list_projects_having_history_retention()

View Source
@spec list_projects_having_history_retention() ::
  [] | [Lightning.Projects.Project.t(), ...]

Lists all projects that have history retention

Link to this function

member_of?(project, user)

View Source

Perform, when called with %{"type" => "purge_deleted"} will find projects that are ready for permanent deletion and purge them.

Link to this function

project_credentials_query(project)

View Source
Link to this function

project_dataclips_query(project)

View Source
Link to this function

project_jobs_query(project)

View Source
Link to this function

project_run_step_query(project)

View Source
Link to this function

project_runs_query(project)

View Source
Link to this function

project_steps_query(project)

View Source
Link to this function

project_triggers_query(project)

View Source
Link to this function

project_user_role_query(user, project)

View Source
@spec project_user_role_query(
  user :: Lightning.Accounts.User.t(),
  project :: Lightning.Projects.Project.t()
) :: Ecto.Queryable.t()
Link to this function

project_users_query(project)

View Source
@spec project_users_query(atom() | %{:id => any(), optional(any()) => any()}) ::
  Ecto.Query.t()
Link to this function

project_workflows_query(project)

View Source
Link to this function

project_workorders_query(project)

View Source
Link to this function

projects_for_user_query(user, opts \\ [])

View Source
@spec projects_for_user_query(user :: Lightning.Accounts.User.t(), opts :: keyword()) ::
  Ecto.Queryable.t()

Builds a query to retrieve projects associated with a user.

Parameters

  • user: The user struct for which projects are being queried.
  • opts: Keyword list of options including :include for associations to preload and :order_by for sorting.

Returns

  • An Ecto queryable struct to fetch projects.

Should input or output dataclips be saved for runs in this project?

Link to this function

schedule_project_deletion(project)

View Source

Given a project, this function sets a scheduled deletion date based on the PURGE_DELETED_AFTER_DAYS environment variable. If no ENV is set, this date defaults to NOW but the automatic project purge cronjob will never run. (Note that subsequent logins will be blocked for projects pending deletion.)

Link to this function

select_first_project_for_user(user)

View Source
@spec select_first_project_for_user(user :: Lightning.Accounts.User.t()) ::
  Lightning.Projects.Project.t() | nil
Link to this function

update_project(project, attrs, user \\ nil)

View Source

Updates a project.

Examples

iex> update_project(project, %{field: new_value})
{:ok, %Project{}}

iex> update_project(project, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

update_project_user(project_user, attrs)

View Source

Updates a project user.

Examples

iex> update_project_user(project_user, %{field: new_value})
{:ok, %ProjectUser{}}

iex> update_project_user(projectUser, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

update_project_with_users(project, attrs, notify_users \\ true)

View Source
@spec update_project_with_users(Lightning.Projects.Project.t(), map(), boolean()) ::
  {:ok, Lightning.Projects.Project.t()} | {:error, Ecto.Changeset.t()}
Link to this function

validate_for_deletion(project, attrs)

View Source

Returns an %Ecto.Changeset{} for changing the project scheduled_deletion.

Examples

iex> validate_for_deletion(project)
%Ecto.Changeset{data: %Project{}}