Giter Club home page Giter Club logo

Comments (2)

linear avatar linear commented on July 23, 2024

HIG-4729 Permissions for turning on AI features (only allow admins to do this)

from highlight.

greptile-apps avatar greptile-apps commented on July 23, 2024

To restrict turning on AI features to admins only, update the EditWorkspaceSettings resolver in /backend/private-graph/graph/schema.resolvers.go to include an admin role check:

func (r *mutationResolver) EditWorkspaceSettings(ctx context.Context, workspaceID int, aiApplication *bool, aiInsights *bool) (*model.AllWorkspaceSettings, error) {
	_, err := r.isUserWorkspaceAdmin(ctx, workspaceID)
	if err != nil {
		return nil, err
	}

	// Add admin role check
	admin, err := r.getCurrentAdmin(ctx)
	if err != nil {
		return nil, err
	}
	if admin.Role != model.AdminRoleAdmin {
		return nil, errors.New("only admins can enable AI features")
	}

	workspaceSettings := &model.AllWorkspaceSettings{}
	workspaceSettingsUpdates := map[string]interface{}{
		"AIApplication": *aiApplication,
		"AIInsights":    *aiInsights,
	}

	if err := store.AssertRecordFound(r.DB.WithContext(ctx).Where(&model.AllWorkspaceSettings{WorkspaceID: workspaceID}).Model(&workspaceSettings).Clauses(clause.Returning{}).Updates(&workspaceSettingsUpdates)); err != nil {
		return nil, err
	}
	return workspaceSettings, nil
}

References

/backend/private-graph/graph/resolver.go
/backend/private-graph/graph/schema.resolvers.go
/frontend/src/pages/IntegrationsPage/IntegrationsPage.tsx
/backend/model/model.go
/frontend/src/pages/WorkspaceTeam/components/AllMembers.tsx

Ask Greptile

from highlight.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.