Exemple #1
0
func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) {
	if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
		c.Err = model.NewLocAppError("getOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "")
		c.Err.StatusCode = http.StatusNotImplemented
		return
	}

	if !HasPermissionToContext(c, model.PERMISSION_MANAGE_OAUTH) {
		c.Err = model.NewLocAppError("getOAuthApps", "api.command.admin_only.app_error", nil, "")
		c.Err.StatusCode = http.StatusForbidden
		return
	}

	var ochan store.StoreChannel
	if HasPermissionToContext(c, model.PERMISSION_MANAGE_SYSTEM_WIDE_OAUTH) {
		ochan = Srv.Store.OAuth().GetApps()
	} else {
		c.Err = nil
		ochan = Srv.Store.OAuth().GetAppByUser(c.Session.UserId)
	}

	if result := <-ochan; result.Err != nil {
		c.Err = result.Err
		return
	} else {
		apps := result.Data.([]*model.OAuthApp)
		w.Write([]byte(model.OAuthAppListToJson(apps)))
	}
}
Exemple #2
0
func getOAuthApps(c *Context, w http.ResponseWriter, r *http.Request) {
	if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
		c.Err = model.NewLocAppError("getOAuthAppsByUser", "api.oauth.allow_oauth.turn_off.app_error", nil, "")
		c.Err.StatusCode = http.StatusNotImplemented
		return
	}

	isSystemAdmin := c.IsSystemAdmin()

	if *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations {
		if !isSystemAdmin {
			c.Err = model.NewLocAppError("getOAuthAppsByUser", "api.command.admin_only.app_error", nil, "")
			c.Err.StatusCode = http.StatusForbidden
			return
		}
	}

	var ochan store.StoreChannel
	if isSystemAdmin {
		ochan = Srv.Store.OAuth().GetApps()
	} else {
		ochan = Srv.Store.OAuth().GetAppByUser(c.Session.UserId)
	}

	if result := <-ochan; result.Err != nil {
		c.Err = result.Err
		return
	} else {
		apps := result.Data.([]*model.OAuthApp)
		w.Write([]byte(model.OAuthAppListToJson(apps)))
	}
}
Exemple #3
0
func getAuthorizedApps(c *Context, w http.ResponseWriter, r *http.Request) {
	if !utils.Cfg.ServiceSettings.EnableOAuthServiceProvider {
		c.Err = model.NewLocAppError("getAuthorizedApps", "api.oauth.allow_oauth.turn_off.app_error", nil, "")
		c.Err.StatusCode = http.StatusNotImplemented
		return
	}

	ochan := Srv.Store.OAuth().GetAuthorizedApps(c.Session.UserId)
	if result := <-ochan; result.Err != nil {
		c.Err = result.Err
		return
	} else {
		apps := result.Data.([]*model.OAuthApp)
		for k, a := range apps {
			a.Sanitize()
			apps[k] = a
		}

		w.Write([]byte(model.OAuthAppListToJson(apps)))
	}
}