Skip to content

Commit

Permalink
frontend, python, cli: allow admins to set storage for new projects
Browse files Browse the repository at this point in the history
See fedora-copr#2533

This will be useful for beaker tests where we can now add basic tests
for every supported storage.
  • Loading branch information
FrostyX committed Sep 5, 2024
1 parent 18f4ea2 commit 7d208bd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
8 changes: 8 additions & 0 deletions cli/copr_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def action_create(self, args):
runtime_dependencies=args.runtime_dependencies,
packit_forge_projects_allowed=args.packit_forge_projects_allowed,
repo_priority=args.repo_priority,
storage=args.storage,
)

owner_part = username.replace('@', "g/")
Expand Down Expand Up @@ -1192,6 +1193,13 @@ def setup_parser():
help=("Use the priority=<INT> config option for repositories in this "
"project, see man dnf.conf(5) for more info."))

parser_create.add_argument(
"--storage",
choices=["backend", "pulp"],
help=("What storage should be set for new projects. "
"This option can only be specified by a COPR admin.")
)

create_and_modify_common_opts(parser_create)

parser_create.set_defaults(func="action_create")
Expand Down
6 changes: 6 additions & 0 deletions frontend/coprs_frontend/coprs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,12 @@ class CoprForm(BaseForm):
default=None,
)

storage = wtforms.SelectField(
"Admin only - what storage should be set for new projects",
choices=[(x, x) for x in ["backend", "pulp"]],
validators=[wtforms.validators.Optional()],
)

@property
def errors(self):
"""
Expand Down
8 changes: 6 additions & 2 deletions frontend/coprs_frontend/coprs/logic/coprs_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def get_multiple_fulltext(cls, fulltext=None, projectname=None,
def add(cls, user, name, selected_chroots, repos=None, description=None,
instructions=None, check_for_duplicates=False, group=None, persistent=False,
auto_prune=True, bootstrap=None, follow_fedora_branching=False, isolation=None,
appstream=False, **kwargs):
appstream=False, storage=None, **kwargs):

if not flask.g.user.admin and flask.g.user != user:
msg = ("You were authorized as '{0}' user without permissions to access "
Expand All @@ -300,6 +300,10 @@ def add(cls, user, name, selected_chroots, repos=None, description=None,
if not flask.g.user.admin and not auto_prune:
raise exceptions.NonAdminCannotDisableAutoPrunning()

if not flask.g.user.admin and storage:
raise exceptions.AccessRestricted("Non-admin cannot set storage")
storage = StorageEnum(storage or app.config["DEFAULT_STORAGE"])

# form validation checks for duplicates
cls.new(user, name, group, check_for_duplicates=check_for_duplicates)

Expand All @@ -315,7 +319,7 @@ def add(cls, user, name, selected_chroots, repos=None, description=None,
isolation=isolation,
follow_fedora_branching=follow_fedora_branching,
appstream=appstream,
storage=StorageEnum(app.config["DEFAULT_STORAGE"]),
storage=storage,
**kwargs)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def _form_field_repos(form_field):
form.packit_forge_projects_allowed
),
repo_priority=form.repo_priority.data,
storage=form.storage.data,
)
db.session.commit()
except (
Expand Down
4 changes: 1 addition & 3 deletions frontend/coprs_frontend/tests/test_apiv3/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ def test_update_copr_api3(self):
}, {
}, {
"appstream": True,
}, {
"storage": StorageEnum("backend"),
}]

for setup in easy_changes:
Expand All @@ -168,7 +166,7 @@ def test_update_copr_api3(self):
"created_on", "deleted", "scm_api_auth_json", "scm_api_type",
"scm_repo_url", "id", "name", "user_id", "group_id",
"webhook_secret", "forked_from_id", "latest_indexed_data_update",
"copr_id", "persistent", "playground",
"copr_id", "persistent", "playground", "storage",
]:
should_test.remove(item)

Expand Down
4 changes: 3 additions & 1 deletion python/copr/v3/proxies/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
delete_after_days=None, multilib=False, module_hotfixes=False,
bootstrap=None, bootstrap_image=None, isolation=None, follow_fedora_branching=True,
fedora_review=None, appstream=False, runtime_dependencies=None, packit_forge_projects_allowed=None,
repo_priority=None, exist_ok=False):
repo_priority=None, exist_ok=False, storage=None):
"""
Create a project
Expand Down Expand Up @@ -110,6 +110,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
enabled together with this project repository.
:param list packit_forge_projects_allowed: List of forge projects that
will be allowed to build in the project via Packit
:param str storage: What storage should be set for new projects
:return: Munch
"""
endpoint = "/project/add/{ownername}"
Expand Down Expand Up @@ -142,6 +143,7 @@ def add(self, ownername, projectname, chroots, description=None, instructions=No
"runtime_dependencies": runtime_dependencies,
"packit_forge_projects_allowed": packit_forge_projects_allowed,
"repo_priority": repo_priority,
"storage": storage,
}

_compat_use_bootstrap_container(data, use_bootstrap_container)
Expand Down

0 comments on commit 7d208bd

Please sign in to comment.