Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [Usage](#usage)
- [Database Schema](#database-schema)
- [Development](#development) - [Prerequisites](#prerequisites) -
[Building](#building) - [Running Tests](#running-tests)
[Building](#building) - [Running Tests](#running-tests)
<!--toc:end-->

A gRPC-based microservice for Hackagon.
Expand Down
2 changes: 1 addition & 1 deletion components/backend/cmd/seed/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (h *harness) createQuestions(
Label: spec.label,
Type: spec.qType,
Mandatory: spec.mandatory,
Order: int32(i + 1), //nolint:gosec // a form has a handful of fields
Order: int32(i + 1),
Options: spec.options,
PublicAnswers: spec.publicAnswers,
})
Expand Down
2 changes: 1 addition & 1 deletion components/backend/cmd/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func main() {
}

// Listen
lc := net.ListenConfig{} //nolint:exhaustruct // all fields optional
lc := net.ListenConfig{} //nolint:exhaustruct_v5 // all fields optional
lis, err := lc.Listen(context.Background(), "tcp", fmt.Sprintf(":%s", cfg.Server.Port))
if err != nil {
logx.Fatal("listen", "err", err)
Expand Down
78 changes: 44 additions & 34 deletions components/backend/internal/middleware/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,79 +173,89 @@ func NewRBACEnforcer(cfg *config.Config) (*Enforcer, error) {
return &Enforcer{enforcer: e}, nil
}

// Casbin domain patterns. The `*` stands in for any id, so a policy written
// against these applies in every hackathon rather than to one in particular.
const (
anyHackathonPath = "/hackathon/*"
anyTeamPath = "/hackathon/*/team/*"
)

func defaultPolicies(cfg *config.Config, e *casbin.Enforcer) error {
policies := [][]string{
// HackathonOrganizer can create new hackathons
{HackathonOrganizer.String(), "/hackathon/*", Hackathon.String(), Create.String()},
{HackathonOrganizer.String(), anyHackathonPath, Hackathon.String(), Create.String()},
// Owner can read owned hackathon
{Owner.String(), "/hackathon/*", Hackathon.String(), Read.String()},
{Owner.String(), anyHackathonPath, Hackathon.String(), Read.String()},
// Owners can view it, which Read does not imply.
{Owner.String(), "/hackathon/*", Hackathon.String(), View.String()},
{Owner.String(), anyHackathonPath, Hackathon.String(), View.String()},
// Owner can write owned hackathon
{Owner.String(), "/hackathon/*", Hackathon.String(), Write.String()},
{Owner.String(), anyHackathonPath, Hackathon.String(), Write.String()},
// Owner can write owned hackathon pages
{Owner.String(), "/hackathon/*", Page.String(), Write.String()},
{Owner.String(), anyHackathonPath, Page.String(), Write.String()},
// Owner can write owned hackathon pages
{Owner.String(), "/hackathon/*", Page.String(), Read.String()},
{Owner.String(), anyHackathonPath, Page.String(), Read.String()},
// Owner can write owned hackathon phases
{Owner.String(), "/hackathon/*", Phase.String(), Write.String()},
{Owner.String(), anyHackathonPath, Phase.String(), Write.String()},
// Owner can write owned hackathon phases
{Owner.String(), "/hackathon/*", Phase.String(), Read.String()},
{Owner.String(), anyHackathonPath, Phase.String(), Read.String()},
// Owner can write owned hackathon tracks
{Owner.String(), "/hackathon/*", Track.String(), Write.String()},
{Owner.String(), anyHackathonPath, Track.String(), Write.String()},
// Owner can read owned hackathon tracks
{Owner.String(), "/hackathon/*", Track.String(), Read.String()},
{Owner.String(), anyHackathonPath, Track.String(), Read.String()},
// Owner can write owned hackathon projects
{Owner.String(), "/hackathon/*", Project.String(), Write.String()},
{Owner.String(), anyHackathonPath, Project.String(), Write.String()},
// Project Owner can write owned project
{Owner.String(), "/hackathon/*/project/*", Project.String(), Write.String()},
// Owner can read owned hackathon projects
{Owner.String(), "/hackathon/*", Project.String(), Read.String()},
{Owner.String(), anyHackathonPath, Project.String(), Read.String()},
// Owner can propose owned hackathon projects
{Owner.String(), "/hackathon/*", Project.String(), Propose.String()},
{Owner.String(), anyHackathonPath, Project.String(), Propose.String()},
// Member can read joined hackathon
{Member.String(), "/hackathon/*", Hackathon.String(), Read.String()},
{Member.String(), anyHackathonPath, Hackathon.String(), Read.String()},
// Member can view it, which Read does not imply.
{Member.String(), "/hackathon/*", Hackathon.String(), View.String()},
{Member.String(), anyHackathonPath, Hackathon.String(), View.String()},
// Member can read hackathon pages
{Member.String(), "/hackathon/*", Page.String(), Read.String()},
{Member.String(), anyHackathonPath, Page.String(), Read.String()},
// Member can read hackathon phases
{Member.String(), "/hackathon/*", Phase.String(), Read.String()},
{Member.String(), anyHackathonPath, Phase.String(), Read.String()},
// Member can read hackathon tracks
{Member.String(), "/hackathon/*", Track.String(), Read.String()},
{Member.String(), anyHackathonPath, Track.String(), Read.String()},
// Member can read hackathon projects
{Member.String(), "/hackathon/*", Project.String(), Read.String()},
{Member.String(), anyHackathonPath, Project.String(), Read.String()},
// Owner can create teams
{Owner.String(), "/hackathon/*", Team.String(), Create.String()},
{Owner.String(), anyHackathonPath, Team.String(), Create.String()},
// Owner can read teams
{Owner.String(), "/hackathon/*", Team.String(), Read.String()},
{Owner.String(), anyHackathonPath, Team.String(), Read.String()},
// Owner can edit teams
{Owner.String(), "/hackathon/*", Team.String(), Write.String()},
{Owner.String(), anyHackathonPath, Team.String(), Write.String()},
// Team member can edit team
{Member.String(), "/hackathon/*/team/*", Team.String(), Write.String()},
{Member.String(), anyTeamPath, Team.String(), Write.String()},
// Team member can edit a submission
{Member.String(), "/hackathon/*/team/*", Submission.String(), Write.String()},
{Member.String(), anyTeamPath, Submission.String(), Write.String()},
// Team member can read a submission
{Member.String(), "/hackathon/*/team/*", Submission.String(), Read.String()},
{Member.String(), anyTeamPath, Submission.String(), Read.String()},
// Hackathon owner can read a submission
{Owner.String(), "/hackathon/*", Submission.String(), Read.String()},
{Owner.String(), anyHackathonPath, Submission.String(), Read.String()},
// Owner can manage vote categories
{Owner.String(), "/hackathon/*", VoteCategory.String(), Create.String()},
{Owner.String(), "/hackathon/*", VoteCategory.String(), Read.String()},
{Owner.String(), "/hackathon/*", VoteCategory.String(), Write.String()},
{Owner.String(), anyHackathonPath, VoteCategory.String(), Create.String()},
{Owner.String(), anyHackathonPath, VoteCategory.String(), Read.String()},
{Owner.String(), anyHackathonPath, VoteCategory.String(), Write.String()},
// Owner can manage vote results
{Owner.String(), "/hackathon/*", VoteResult.String(), Create.String()},
{Owner.String(), "/hackathon/*", VoteResult.String(), Read.String()},
{Owner.String(), "/hackathon/*", VoteResult.String(), Write.String()},
{Owner.String(), "/hackathon/*", Vote.String(), Read.String()},
{Owner.String(), anyHackathonPath, VoteResult.String(), Create.String()},
{Owner.String(), anyHackathonPath, VoteResult.String(), Read.String()},
{Owner.String(), anyHackathonPath, VoteResult.String(), Write.String()},
{Owner.String(), anyHackathonPath, Vote.String(), Read.String()},
}

// AddPoliciesEx adds what is missing and skips the rest.
if _, err := e.AddPoliciesEx(policies); err != nil {
return fmt.Errorf("couldn't load grouping policies: %w", err)
}

if _, err := e.AddNamedGroupingPolicy("g2", []string{cfg.Server.AdminKeycloakID, "admin"}); err != nil {
if _, err := e.AddNamedGroupingPolicy(
"g2",
[]string{cfg.Server.AdminKeycloakID, "admin"},
); err != nil {
return fmt.Errorf("couldn't add default admin: %w", err)
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading