agents get read, not write, on their own agent-configs repo; an existing grant is left alone
This commit is contained in:
parent
144d958208
commit
07c66e3a1c
3 changed files with 35 additions and 41 deletions
|
|
@ -524,17 +524,6 @@ impl Client {
|
|||
}
|
||||
}
|
||||
|
||||
/// Add `user` as a collaborator on `CONFIG_ORG/repo` at `permission`.
|
||||
async fn add_collaborator(
|
||||
&self,
|
||||
repo: &str,
|
||||
user: &str,
|
||||
permission: AddCollaboratorOptionPermission,
|
||||
) -> Result<()> {
|
||||
self.add_collaborator_to(CONFIG_ORG, repo, user, permission)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Add `user` as a collaborator on `owner/repo` at `permission`.
|
||||
/// Idempotent: re-adding an existing collaborator just updates its
|
||||
/// permission (forgejo answers 204 either way; a 201 from older
|
||||
|
|
@ -720,12 +709,14 @@ impl Client {
|
|||
Ok(true)
|
||||
}
|
||||
|
||||
/// Add `agent` as a **write** collaborator on `repo` (can push + open
|
||||
/// PRs, cannot bypass branch protection) — the whole job of the
|
||||
/// `AddRepoMember` node. Idempotent.
|
||||
/// Add `agent` as a **read** collaborator on `repo` — the whole job of the
|
||||
/// `AddRepoMember` node. Read is enough: the agent clones its config and
|
||||
/// proposes a change through an `AGit` pull request, which needs no push
|
||||
/// access. Idempotent, and it leaves a grant of read or more as it is, so a
|
||||
/// write grant an operator made, or one made before this node granted
|
||||
/// read, is never lowered.
|
||||
pub async fn add_repo_member(&self, repo: &str, agent: &str) -> Result<()> {
|
||||
self.add_collaborator(repo, agent, AddCollaboratorOptionPermission::Write)
|
||||
.await
|
||||
self.grant_read(CONFIG_ORG, repo, agent).await
|
||||
}
|
||||
|
||||
/// Ensure `agent` exists as a Forgejo user account that cannot create
|
||||
|
|
|
|||
|
|
@ -54,15 +54,21 @@ fn holds_read(p: &RepoCollaboratorPermission) -> bool {
|
|||
|
||||
impl Client {
|
||||
/// Make `agent` a **read** collaborator on `internal/docs` — the whole job
|
||||
/// of the `GrantDocsRead` node. Idempotent, and never lowers: an agent that
|
||||
/// already holds read or more (write, admin, owner) is left as it is, since
|
||||
/// the add endpoint would overwrite the permission. Needs the forge user to
|
||||
/// exist.
|
||||
/// of the `GrantDocsRead` node. Idempotent, and never lowers: see
|
||||
/// [`Self::grant_read`]. Needs the forge user to exist.
|
||||
pub async fn grant_docs_read(&self, agent: &str) -> Result<()> {
|
||||
self.grant_read(SHARED_ORG, SHARED_DOCS_REPO, agent).await
|
||||
}
|
||||
|
||||
/// Make `user` a **read** collaborator on `owner/repo` unless it already
|
||||
/// holds read or more (write, admin, owner), which is left as it is: the
|
||||
/// add endpoint would overwrite the permission, so adding at read would
|
||||
/// lower a write grant an operator made.
|
||||
pub(super) async fn grant_read(&self, owner: &str, repo: &str, user: &str) -> Result<()> {
|
||||
match self
|
||||
.api
|
||||
.call(|api| {
|
||||
api.repo_get_repo_permissions(SHARED_ORG, SHARED_DOCS_REPO, agent)
|
||||
api.repo_get_repo_permissions(owner, repo, user)
|
||||
.into_future()
|
||||
})
|
||||
.await
|
||||
|
|
@ -71,18 +77,12 @@ impl Client {
|
|||
Ok(_) => {}
|
||||
Err(e) if is_not_found(&e) => {}
|
||||
Err(e) => {
|
||||
return Err(e).with_context(|| {
|
||||
format!("read {agent}'s permission on {SHARED_ORG}/{SHARED_DOCS_REPO}")
|
||||
});
|
||||
return Err(e)
|
||||
.with_context(|| format!("read {user}'s permission on {owner}/{repo}"));
|
||||
}
|
||||
}
|
||||
self.add_collaborator_to(
|
||||
SHARED_ORG,
|
||||
SHARED_DOCS_REPO,
|
||||
agent,
|
||||
AddCollaboratorOptionPermission::Read,
|
||||
)
|
||||
.await
|
||||
self.add_collaborator_to(owner, repo, user, AddCollaboratorOptionPermission::Read)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Whether `agent` is a collaborator on `internal/docs` now.
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ pub(crate) enum SwarmNodeKind {
|
|||
/// account this node hasn't created yet. See
|
||||
/// `forge::Client::ensure_agent_user`.
|
||||
CreateForgeUser { agent: String },
|
||||
/// Add `agent` as a write collaborator on its own repo. See
|
||||
/// Add `agent` as a read collaborator on its own repo. See
|
||||
/// `forge::Client::add_repo_member`.
|
||||
AddRepoMember { agent: String },
|
||||
/// Add `agent` as a read collaborator on `internal/docs`. See
|
||||
|
|
|
|||
Loading…
Reference in a new issue