Skip to content

Commit 2ab1fb7

Browse files
authored
Merge branch 'Ericsson:master' into provider-gitlab-addition
2 parents c27f211 + 99a4952 commit 2ab1fb7

File tree

8 files changed

+56
-22
lines changed

8 files changed

+56
-22
lines changed

.github/workflows/codechecker_master_analysis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,5 @@ jobs:
3232
CODECHECKER_TOKEN: ${{ secrets.CODECHECKER_STORE_TOKEN }}
3333
PR_NUMBER: ${{ github.event.number }}
3434
run: |
35-
pwd
36-
ls
37-
touch ~/.codechecker.passwords.json
38-
chmod 0600 ~/.codechecker.passwords.json
3935
echo "{\"client_autologin\" : true,\"credentials\": {\"*\": \"store:$CODECHECKER_TOKEN\"}}" > ~/.codechecker.passwords.json
4036
bash ./ci/github_analysis/codechecker_gate_master.sh

.github/workflows/codechecker_pr_analysis.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
name: codechecker-pr-analysis
22

33
# Triggers the workflow on push or pull request events.
4-
on: [push, pull_request]
4+
on:
5+
pull_request:
6+
types: [opened, edited, reopened, synchronize]
57

68
jobs:
79
codechecker-pr-analyis:
@@ -29,10 +31,5 @@ jobs:
2931
CODECHECKER_TOKEN: ${{ secrets.CODECHECKER_STORE_TOKEN }}
3032
PR_NUMBER: ${{ github.event.number }}
3133
run: |
32-
pwd
33-
ls
34-
CodeChecker version
35-
touch ~/.codechecker.passwords.json
36-
chmod 0600 ~/.codechecker.passwords.json
37-
echo "{\"client_autologin\" : true,\"credentials\": {\"https://codechecker-demo.eastus.cloudapp.azure.com\": \"store:$CODECHECKER_TOKEN\"}}" > ~/.codechecker.passwords.json
34+
echo "{\"client_autologin\" : true,\"credentials\": {\"https://codechecker-demo.eastus.cloudapp.azure.com\": \"store:${CODECHECKER_TOKEN}\"}}" > ~/.codechecker.passwords.json
3835
bash ./ci/github_analysis/codechecker_gate_pr.sh $GITHUB_REF

web/server/codechecker_server/api/product_server.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ def __get_product(self, session, product):
123123

124124
args = {'config_db_session': session,
125125
'productID': product.id}
126-
product_access = permissions.require_permission(
126+
127+
has_product_permission = permissions.require_permission(
127128
permissions.PRODUCT_VIEW, args, self.__auth_session)
129+
has_global_permission = permissions.require_permission(
130+
permissions.PERMISSION_VIEW, args, self.__auth_session)
131+
has_access_permission = has_product_permission or has_global_permission
128132

129133
admin_perm_name = permissions.PRODUCT_ADMIN.name
130134
admins = session.query(ProductPermission). \
@@ -154,7 +158,7 @@ def __get_product(self, session, product):
154158
runCount=product.num_of_runs,
155159
latestStoreToProduct=latest_storage_date,
156160
connected=connected,
157-
accessible=product_access,
161+
accessible=has_access_permission,
158162
administrating=self.__administrating(args),
159163
databaseStatus=server_product.db_status,
160164
admins=[admin.name for admin in admins],
@@ -260,9 +264,10 @@ def getProductConfiguration(self, product_id):
260264
Get the product configuration --- WITHOUT THE DB PASSWORD --- of the
261265
given product.
262266
"""
263-
self.__require_permission([permissions.PRODUCT_VIEW], {
264-
'productID': product_id
265-
})
267+
self.__require_permission([
268+
permissions.PRODUCT_VIEW,
269+
permissions.PERMISSION_VIEW
270+
], {'productID': product_id})
266271

267272
with DBSession(self.__session) as session:
268273
product = session.query(Product).get(product_id)

web/server/codechecker_server/api/report_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,10 @@ def __require_store(self):
14681468
self.__require_permission([permissions.PRODUCT_STORE])
14691469

14701470
def __require_view(self):
1471-
self.__require_permission([permissions.PRODUCT_VIEW])
1471+
self.__require_permission([
1472+
permissions.PRODUCT_VIEW,
1473+
permissions.PERMISSION_VIEW
1474+
])
14721475

14731476
def __add_comment(self, bug_id, message, kind=CommentKindValue.USER,
14741477
date=None):

web/server/codechecker_server/session_manager.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def __try_personal_access_token(self, auth_string):
592592

593593
return {
594594
'username': personal_access_token.user_name,
595-
'groups': personal_access_token.groups
595+
'groups': str(personal_access_token.groups).split(";")
596596
}
597597

598598
def __try_auth_dictionary(self, auth_string):
@@ -616,6 +616,8 @@ def __try_auth_dictionary(self, auth_string):
616616
'groups' in method_config and \
617617
username in method_config['groups'] else []
618618

619+
self.__update_personal_access_token_groups(username, group_list)
620+
619621
return {
620622
'username': username,
621623
'groups': group_list
@@ -648,10 +650,39 @@ def __try_auth_ldap(self, auth_string):
648650
if cc_ldap.auth_user(ldap_conf, username, password):
649651
groups = cc_ldap.get_groups(ldap_conf, username, password)
650652
self.__update_groups(username, groups)
653+
self.__update_personal_access_token_groups(
654+
username,
655+
groups
656+
)
651657
return {'username': username, 'groups': groups}
652658

653659
return False
654660

661+
def __update_personal_access_token_groups(self, user_name, groups):
662+
"""
663+
Update the groups assigned to a personal access token.
664+
"""
665+
if not self.__database_connection:
666+
return None
667+
668+
transaction = None
669+
try:
670+
transaction = self.__database_connection()
671+
transaction.query(PersonalAccessToken) \
672+
.filter(PersonalAccessToken.user_name == user_name) \
673+
.update({PersonalAccessToken.groups: ';'.join(groups)})
674+
transaction.commit()
675+
return True
676+
except Exception as e:
677+
LOG.error(
678+
f"Couldn't find personal access token for user "
679+
f"{user_name}: {str(e)}")
680+
finally:
681+
if transaction:
682+
transaction.close()
683+
684+
return False
685+
655686
def __update_groups(self, user_name, groups):
656687
"""
657688
Updates group field of the users tokens.
@@ -839,6 +870,8 @@ def create_session_oauth(self, provider: str,
839870

840871
self.__sessions.append(local_session)
841872

873+
self.__update_personal_access_token_groups(username, groups)
874+
842875
# Store the session in the database.
843876
transaction = None
844877
if self.__database_connection:

web/server/vue-cli/src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ router.beforeResolve((to, from, next) => {
6464
store.dispatch(GET_AUTH_PARAMS).then(() => {
6565
if (to.matched.some(record => record.meta.requiresAuth)) {
6666
if (store.getters.authParams.requiresAuthentication &&
67-
!store.getters.isAuthenticated
67+
(!store.getters.authParams.sessionStillActive ||
68+
!store.getters.isAuthenticated)
6869
) {
6970
// Redirect the user to the login page but keep the original path to
7071
// redirect the user back once logged in.

web/server/vue-cli/src/store/modules/auth.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ const getters = {
3737

3838
const actions = {
3939
[GET_AUTH_PARAMS]({ commit }) {
40-
if (state.authParams) return state.authParams;
41-
4240
return new Promise(resolve => {
4341
authService.getClient().getAuthParameters(
4442
handleThriftError(params => {

web/server/vue-cli/src/views/Login.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default {
167167
168168
computed: {
169169
...mapGetters([
170+
"authParams",
170171
"isAuthenticated"
171172
]),
172173
ssoButtonText() {
@@ -185,7 +186,7 @@ export default {
185186
},
186187
187188
created() {
188-
if (this.isAuthenticated) {
189+
if (this.isAuthenticated && this.authParams.sessionStillActive) {
189190
const returnTo = this.$router.currentRoute.query["return_to"];
190191
this.$router.replace(returnTo || { name: "products" });
191192
}

0 commit comments

Comments
 (0)