Project Visibility, project features, permissions settings API

Hi,

this is my first time jumping into specific toggles via API, and now it is evening and couch time, so I can dig a little deeper. Also for anyone else looking into the issue - the code is located here: https://gitlab.com/dnsmichi/api-playground

Setup python-gitlab

pip install python-gitlab
vim $HOME/.python-gitlab.cfg

[global]
default = gitlab.com

[gitlab.com]
url = https://gitlab.com
private_token = xxx
api_version = 4
ssl_verify = true

Simple query

#!/usr/bin/env python

import gitlab

PROJECT_ID=15013654

gl = gitlab.Gitlab.from_config('gitlab.com', ['/Users/michi/.python-gitlab.cfg'])

print("Project attributes required for creation")
print(gl.projects.get_create_attrs())

project = gl.projects.get(PROJECT_ID)
print("All project attributes")
print(project.attributes)

print("Project attributes matching access_level")
for a in project.attributes:
    if "access_level" in a:
        print(a)

Tests

The last loop says the same, the pages_access_level is not there, but the feature is actually there and enabled.

Project attributes matching access_level
builds_access_level
snippets_access_level
repository_access_level
issues_access_level
merge_requests_access_level
wiki_access_level

I’d say that I can reproduce the problem, but I don’t know if that’s a bug within GitLab’s API to not expose these settings. They clearly exist via the config form, as can be seen with Chrome’s dev console.

Let’s dig deeper in the code

The above list says, that we can e.g. control wiki_access_level.

grep -r pages_access_level .

vs

grep -r wiki_access_level .

./lib/api/entities.rb:      expose(:wiki_access_level) { |project, options| project.project_feature.string_access_level(:wiki) }
./lib/api/helpers/projects_helpers.rb:        optional :wiki_access_level, type: String, values: %w(disabled private enabled), desc: 'Wiki access level. One of `disabled`, `private` or `enabled`'
./lib/api/helpers/projects_helpers.rb:          :wiki_access_level,

./doc/api/projects.md:| `wiki_enabled` | boolean | no | (deprecated) Enable wiki for this project. Use `wiki_access_level` instead |
./doc/api/projects.md:| `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` |
./doc/api/projects.md:| `wiki_enabled` | boolean | no | (deprecated) Enable wiki for this project. Use `wiki_access_level` instead |
./doc/api/projects.md:| `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` |
./doc/api/projects.md:| `wiki_enabled` | boolean | no | (deprecated) Enable wiki for this project. Use `wiki_access_level` instead |
./doc/api/projects.md:| `wiki_access_level` | string | no | One of `disabled`, `private` or `enabled` |

So, we’ve got a winner. The attribute is not implemented in the API entity.

Feature Request?

Well, actually, I’ve found issues already requesting that where I will link this topic too to raise awareness.


Merge Request?

When looking into an MR, I’ve found another example to learn from at

Let’s see how far my journey goes :wink:

Edit: Let’s try it.

Cheers,
Michael

1 Like