Skip to content

Commit 8ff1ca5

Browse files
committed
Merge remote-tracking branch 'origin/main' into main-branch-sync
2 parents 8c993ce + b37bf8d commit 8ff1ca5

File tree

8 files changed

+243
-178
lines changed

8 files changed

+243
-178
lines changed

.github/workflows/auto-label.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
issue_comment:
55
types: [created]
66

7-
87
jobs:
98
manage-labels:
109
if: ${{ !github.event.issue.pull_request }}
@@ -16,40 +15,37 @@ jobs:
1615

1716
- name: Parse and manage labels
1817
env:
19-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
GH_TOKEN: ${{ secrets.ORG_MEMBERSHIP_SECRET }}
2019
run: |
2120
set -e
2221
set -x # Enable debugging
2322
24-
# Extract comment on body and issue number
23+
# Extract comment body, issue number, and author
2524
COMMENT_BODY=$(jq -r '.comment.body' "$GITHUB_EVENT_PATH")
2625
ISSUE_NUMBER=$(jq -r '.issue.number // .pull_request.number' "$GITHUB_EVENT_PATH")
26+
COMMENT_AUTHOR=$(jq -r '.comment.user.login' "$GITHUB_EVENT_PATH")
2727
28-
ORG_NAME="devtron-labs"
29-
30-
# checks if the person is authorized to add labels or not
31-
ORG_MEMBERSHIP_STATUS=$(gh api "orgs/$ORG_NAME/members/$COMMENT_AUTHOR" --silent --exit-status)
28+
ORG_NAME="satyam-tests"
3229
30+
# Check if the person is authorized to add labels
31+
curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/orgs/$ORG_NAME/members/$COMMENT_AUTHOR" > /dev/null
3332
if [[ $? -ne 0 ]]; then
3433
gh issue comment "$ISSUE_NUMBER" --body "Hi @$COMMENT_AUTHOR, you must be a member of the organization '$ORG_NAME' to add or remove labels."
35-
3634
echo "User '$COMMENT_AUTHOR' is not a member of the organization '$ORG_NAME'. Exiting."
3735
exit 1
3836
fi
3937
40-
echo "User '$COMMENT_AUTHOR' is a verified member of the organization '$ORG_NAME'. Adding label"
41-
38+
echo "User '$COMMENT_AUTHOR' is a verified member of the organization '$ORG_NAME'. Proceeding with label management."
4239
43-
# Get the existing labels on the issue
40+
# Get the existing labels on the issue
4441
EXISTING_LABELS=$(gh issue view "$ISSUE_NUMBER" --json labels -q '.labels[].name')
4542
46-
# Add Label
43+
# Add Label Logic
4744
if [[ "$COMMENT_BODY" =~ ^/([^ ]+)$ ]]; then
4845
LABEL_NAME="${COMMENT_BODY:1}"
4946
50-
# check for already existing labels in reppo
47+
# Check if the label exists in the repository
5148
if gh label list --json name -q '.[].name' | grep -q "^$LABEL_NAME$"; then
52-
# Add the requested label, keeping existing ones intact
5349
gh issue edit "$ISSUE_NUMBER" --add-label "$LABEL_NAME"
5450
echo "Successfully added label '$LABEL_NAME' to issue #$ISSUE_NUMBER."
5551
else

api/bean/UserRequest.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ type RoleFilter struct {
7272
Workflow string `json:"workflow"`
7373
}
7474

75+
func (rf RoleFilter) GetTeam() string { return rf.Team }
76+
func (rf RoleFilter) GetEntity() string { return rf.Entity }
77+
func (rf RoleFilter) GetAction() string { return rf.Action }
78+
func (rf RoleFilter) GetAccessType() string { return rf.AccessType }
79+
func (rf RoleFilter) GetEnvironment() string { return rf.Environment }
80+
func (rf RoleFilter) GetCluster() string { return rf.Cluster }
81+
func (rf RoleFilter) GetGroup() string { return rf.Group }
82+
func (rf RoleFilter) GetKind() string { return rf.Kind }
83+
func (rf RoleFilter) GetEntityName() string { return rf.EntityName }
84+
func (rf RoleFilter) GetResource() string { return rf.Resource }
85+
func (rf RoleFilter) GetWorkflow() string { return rf.Workflow }
86+
func (rf RoleFilter) GetNamespace() string { return rf.Namespace }
87+
7588
type Role struct {
7689
Id int `json:"id" validate:"number"`
7790
Role string `json:"role" validate:"required"`

pkg/auth/user/RoleGroupService.go

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -569,46 +569,11 @@ func (impl RoleGroupServiceImpl) getRoleGroupMetadata(roleGroup *repository.Role
569569
impl.logger.Errorw("No Roles Found for user", "roleGroupId", roleGroup.Id)
570570
}
571571
var roleFilters []bean.RoleFilter
572-
isSuperAdmin := false
573-
roleFilterMap := make(map[string]*bean.RoleFilter)
574-
for _, role := range roles {
575-
key := impl.userCommonService.GetUniqueKeyForAllEntity(*role)
576-
if _, ok := roleFilterMap[key]; ok {
577-
impl.userCommonService.BuildRoleFilterForAllTypes(roleFilterMap, *role, key)
578-
} else {
579-
roleFilterMap[key] = &bean.RoleFilter{
580-
Entity: role.Entity,
581-
Team: role.Team,
582-
Environment: role.Environment,
583-
EntityName: role.EntityName,
584-
Action: role.Action,
585-
AccessType: role.AccessType,
586-
Cluster: role.Cluster,
587-
Namespace: role.Namespace,
588-
Group: role.Group,
589-
Kind: role.Kind,
590-
Resource: role.Resource,
591-
Workflow: role.Workflow,
592-
}
593-
}
594-
if role.Role == bean.SUPERADMIN {
595-
isSuperAdmin = true
596-
}
597-
}
598-
for _, v := range roleFilterMap {
599-
if v.Action == bean2.SUPER_ADMIN {
600-
continue
601-
}
602-
roleFilters = append(roleFilters, *v)
603-
}
604-
for index, roleFilter := range roleFilters {
605-
if roleFilter.Entity == "" {
606-
roleFilters[index].Entity = bean2.ENTITY_APPS
607-
}
608-
if roleFilter.Entity == bean2.ENTITY_APPS && roleFilter.AccessType == "" {
609-
roleFilters[index].AccessType = bean2.DEVTRON_APP
610-
}
611-
}
572+
isSuperAdmin := helper2.CheckIfSuperAdminFromRoles(roles)
573+
// merging considering base as env first
574+
roleFilters = impl.userCommonService.BuildRoleFiltersAfterMerging(ConvertRolesToEntityProcessors(roles), bean2.EnvironmentBasedKey)
575+
// merging role filters based on application now, first took env as base merged, now application as base , merged
576+
roleFilters = impl.userCommonService.BuildRoleFiltersAfterMerging(ConvertRoleFiltersToEntityProcessors(roleFilters), bean2.ApplicationBasedKey)
612577
if len(roleFilters) == 0 {
613578
roleFilters = make([]bean.RoleFilter, 0)
614579
}

0 commit comments

Comments
 (0)